var page = require('webpage').create();
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 10.0; WOW64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157
Safari/537.36';
page.settings.javascriptEnabled = true;
page.settings.loadImages = false;//Script is much faster with this field
set to false
phantom.cookiesEnabled = true;
phantom.javascriptEnabled = true;
page.onConsoleMessage = function(str) {
console.log(str);
}
page.open('https://www.sulekha.com/local-services/business-
owners/dashboard/', function(status) {
page.render('beforeclick.png');
console.log(page.url);
var element = page.evaluate(function() {
return document.querySelector('.logged-out .signin-btn');
});
console.log(element, '====')
page.sendEvent('click', element.offsetLeft, element.offsetTop, 'left');
// document.getElementById('txtuname').focus();
window.setTimeout(function () {
console.log(page.url);
console.log(document.getElementById('txtuname'), "--0")
page.render('afterclick.png');
phantom.exit();
}, 9000);
console.log('element is ' + element + "-=-");
});
但是它没有点击signin-btn
单击前和单击后的图像相同。 我还添加了超时,但似乎缺少了一些东西