javascript - PhantomJS bug in basic script -
this script pretending log in google account (i've made). obviously, doesn't work. there no particular objective here, make work.
var page = require('webpage').create(); page.onconsolemessage = function(msg) { console.log('console: ' + msg); }; page.open('https://google.com/', function() { page.injectjs('jquery-2.2.1.min.js'); page.evaluate(function() { function include(arr,obj) { // functions not part of scraping return (arr.indexof(obj) != -1); } function add(a, b) { return + b; } array.min = function( array ){ return math.min.apply( math, array ); }; function dofirst() { $('#gb_70').click(); main(1, 0); } function dosecond() { document.getelementbyid('email').value = 'myemail@gmail.com'; $('#next').click(); main(2, 0); } function dothird() { document.getelementbyid('passwd').value = 'p4ssw0rd'; $('#signin').click(); main(3, 0); } function dofourth() { l1 = ['test', 'test2', 'google']; (var = 0; < 1; i++) { if (l1, 'google') { console.log('success!'); } } main(4, 0); } function dofifth() { $('.gb_b.gb_8a.gb_r').click() settimeout(function(){$('#gb_71').click()}, 500); main(0, 5000); } function main(i, j) { if (i === 0) { console.log('launching 0'); settimeout(dofirst(), j); // connections } else if (i === 1) { console.log('launching 1'); settimeout(dosecond(), 5000); } else if (i === 2) { console.log('launching 2'); settimeout(dothird(), 5000); } else if (i === 3) { console.log('launching 3'); settimeout(dofourth(), 5000); } else if (i === 4) { console.log('launching 4'); settimeout(dofifth(), 5000); } } main(0, 5000); }); console('super end'); page.render('google.png'); });
at end errors :
console: launching 0 console: launching 1 typeerror: null not object (evaluating 'document.getelementbyid('email').value = 'myemail@gmail.com'') undefined:7 in dosecond :22 in main :4 in dofirst :18 in main :29 :30
i tried many ways , no 1 worked. make work though python , selenium web driver (which real love). time has passed, , has in javascript (to dom/jquery... web compatible).
can me please make work!
edit 1: trying capture screenshot, save empty png.
edit 2: think may hint, when phantomjs test.js, takes long time load , logs everything...
edit 3: changed document.get(...).value = 'blabla' $('#id').val('blabla'); , prints
console: launching 0 console: launching 1 console: launching 2 console: launching 3 console: success! console: success! console: success! console: success! console: success!
however should prints 1 success, , evidently capture still not work.
for edit 1: trying capture screen
check status make sure page loaded.
page.open(url, function(status) { if (status !== 'success') { // exit if fails load page console.log(status); phantom.exit(1); } else{ // code here } });
Comments
Post a Comment