| 1 | // Read the Phantom webpage '#intro' element text using jQuery and "includeJs" |
| 2 | |
| 3 | "use strict"; |
| 4 | var page = require('webpage').create(); |
| 5 | |
| 6 | page.onConsoleMessage = function(msg) { |
| 7 | console.log(msg); |
| 8 | }; |
| 9 | |
| 10 | page.open("http://phantomjs.org/", function(status) { |
| 11 | if (status === "success") { |
| 12 | page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() { |
| 13 | page.evaluate(function() { |
| 14 | console.log("$(\".explanation\").text() -> " + $(".explanation").text()); |
| 15 | }); |
| 16 | phantom.exit(0); |
| 17 | }); |
| 18 | } else { |
| 19 | phantom.exit(1); |
| 20 | } |
| 21 | }); |