Skip to content

Instantly share code, notes, and snippets.

@JamesMGreene
Created January 13, 2014 14:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesMGreene/8401600 to your computer and use it in GitHub Desktop.
Save JamesMGreene/8401600 to your computer and use it in GitHub Desktop.
Showing Phantom supporting searching for text using the normal browser DOM APIs.
var page = require("webpage").create();
page.onConsoleMessage = function(msg) {
console.log('[PAGE] Message: ' + msg);
};
page.open("http://google.com/", function(status) {
if (status !== "success") {
console.error("Failed to load the page. Usually this means some resource failed to load.");
phantom.exit(1);
return;
}
console.log("Loaded the page successfully!");
page.evaluate(function() {
console.log('`window.find` exists: ' + (!!window.find));
console.log('`typeof window.find`: ' + (typeof window.find));
console.log('result of `window.find("about")`: ' + window.find("about"));
console.log('result of `window.find("BlahBlahBlah")`: ' + window.find("BlahBlahBlah"));
});
phantom.exit(0);
});
$> phantomjs.exe findText.js
Loaded the page successfully!
[PAGE] Message: `window.find` exists: true
[PAGE] Message: `typeof window.find`: function
[PAGE] Message: result of `window.find("about")`: true
[PAGE] Message: result of `window.find("BlahBlahBlah")`: false
$>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment