Created
January 13, 2014 14:49
-
-
Save JamesMGreene/8401600 to your computer and use it in GitHub Desktop.
Showing Phantom supporting searching for text using the normal browser DOM APIs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$> 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