PhantomJS单击页面上的链接 [英] PhantomJS click a link on a page

查看:90
本文介绍了PhantomJS单击页面上的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了PhantomJS应用程序的一些部分。我在一个网站上解析,我在那里写了一个公式的用户名和密码。在此之后,我必须点击链接。虽然我收到此错误:

I have written some parts of a PhantomJS application. I am parsing on a website where I am writing username and password to a formular. After this I have to click on a link. Whereas I get this error:

TypeError: 'undefined' is not a function (evaluating 'myLink.click()')

  phantomjs://webpage.evaluate():11
  phantomjs://webpage.evaluate():22
  phantomjs://webpage.evaluate():22

这是我的PhantomJS代码:

This is my PhantomJS code:

if(document.getElementById("m_Content_submitbtn2").getAttribute('data-role') == "button"){
        var myLink = document.getElementById("m_Content_submitbtn2");   
    myLink.click();
}

这是我的链接:

<div class='button'><a href="#" data-role="button" tabindex='0' onclick='WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;m$Content$submitbtn2&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true)); return false;' id="m_Content_submitbtn2">Log ind</a></div>&nbsp;


推荐答案

您正在尝试使用< a> 元素上单击()方法,默认情况下不支持所有浏览器。而是尝试使用 this 而不是 myLink。 click(); 你必须要做 eventFire(myLink,'click');

You are attempting to use the click() method on an <a> element which is not supported in all browser by default. Instead try using something like this where instead of myLink.click(); you will have to do eventFire(myLink, 'click');.

这篇关于PhantomJS单击页面上的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆