javascript - Sending the keydown event does not work in PhantomJS -


i tried code web page content loaded dynamically when press keydown. (like facebook)

the goal net traffic , print console.

var page = require('webpage').create(),     system = require('system'),     address;  if (system.args.length === 1) {     console.log('usage: netlog.js <some url>');     phantom.exit(1); } else {     address = system.args[1];      page.onloadfinished      = function(req) {         console.log('requested: ' + json.stiringify(req, undefined, 4));      };     page.open(url, function () {         page.sendevent('keypress', page.event.key.keydown);      });     page.onresourcerequested = function (req) {         console.log('requested: ' + json.stringify(req, undefined, 4));     };      page.onresourcereceived = function (res) {         console.log('received: ' + json.stringify(res, undefined, 4));     };       page.open(address, function (status) {         if (status !== 'success') {             console.log('fail load address');         }         phantom.exit();     });  } 

first of all, phantomjs asynchronous. you're opening 2 pages @ same time. when second page.open() loading of first page aborted. means page.sendevent() call never executed.

if want see whether event doing something, need let page load , after doing action wait little see if there requests:

if (system.args.length === 1) {     console.log('usage: netlog.js <some url>');     phantom.exit(1); } else {     address = system.args[1];      page.onresourcerequested = function (req) {         console.log('requested: ' + json.stringify(req, undefined, 4));     };      page.onresourcereceived = function (res) {         console.log('received: ' + json.stringify(res, undefined, 4));     };       page.open(address, function (status) {         if (status !== 'success') {             console.log('fail load address');             phantom.exit(1);         }          page.sendevent('keypress', page.event.key.keydown);           settimeout(function(){             phantom.exit();         }, 1000);     }); } 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -