Phantom JS未单击按钮

时间:2019-05-12 07:40:22

标签: phantomjs

beforclick image and after click image我正在使用幻影js打开页面并尝试单击按钮

   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

单击前和单击后的图像相同。 我还添加了超时,但似乎缺少了一些东西

0 个答案:

没有答案