mirror of
https://github.com/encounter/phantomjs.git
synced 2026-03-30 11:35:11 -07:00
75403737c4
* It includes a script in the page * It uses a callback to ensure any code dependent on the include runs afterwards * It uses the signal "javaScriptAlertSent" to do the trick (is there another way to be notified of the "onLoad" event from outside the page context?) * It uses a "private" slot "_appendScriptElement" to pass the script url in the page context (is there a better way?)
20 lines
551 B
JavaScript
20 lines
551 B
JavaScript
// Read the Phantom webpage '#intro' element text using jQuery and "includeJs"
|
|
|
|
var page = new WebPage();
|
|
|
|
page.onConsoleMessage = function(msg) {
|
|
console.log(msg);
|
|
};
|
|
|
|
page.open("http://www.phantomjs.org", function(status) {
|
|
if ( status === "success" ) {
|
|
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
|
|
page.evaluate(function() {
|
|
console.log("$(\"#intro\").text() -> " + $("#intro").text());
|
|
});
|
|
phantom.exit();
|
|
});
|
|
}
|
|
});
|
|
|