努力点击htmlunit内的链接 [英] struggling to click on link within htmlunit

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

问题描述

点击htmlunit中的链接时遇到问题。我浏览了网站上的api(我真的不太了解)并查看了我能找到的所有示例代码,但仍然遇到点击链接的问题。

I am having a problem clicking on a link within htmlunit. I went through the api on the site(which I didn't really understand well) and looked at all the sample code I could find and am still having a problem with clicking on links.

这是错误消息的顶部(它非常大,如果你想我可以全部提交)

Here's the top of the error messsage(its pretty large, if you want I can submit it all)

"page2 = link2.click() Exception class=[net.sourceforge.htmlunit.corejs.javascript.JavaScriptException] com.gargoylesoftware.htmlunit.ScriptException: Sys.ArgumentOutOfRangeException: Sys.ArgumentOutOfRangeException: Value must be an integer. Parameter name: x Actual value was Infinity. "

第一页加载正常,但当我点击第二个链接时,我得到这个错误(链接是javascript)。这是我的代码的一部分

The first page loads fine but when I click on the second link, I get this error(the link is javascript). Here's parts of my code

       page = webclient.getPage(url) 
   anchors1 =  page.getAnchors()
   for anchor in anchors1:
        if anchor.asText() == "2":
            link2 = anchor
            break
   page2 = link2.click()

如果我打印链接2,我得到: HtmlAnchor [< a href =javascript: __doPostBack('ctl00 $ MainContent $ gvSearchResults','Page $ 2')>]

If I do a print link2 I get: HtmlAnchor[<a href="javascript:__doPostBack('ctl00$MainContent$gvSearchResults','Page$2')">]

起初我觉得HtmlAnchor可能是一个问题,我不得不删除它,但后来我看了其他示例代码,他们似乎有他们的链接以相同的格式结束,它的工作原理。

At first I thought maybe the HtmlAnchor was a problem and I had to remove it but then I looked at other sample code and they seem to have their links end up in the same format and it works.

如此困惑。 .please help: - )

So confused..please help :-)

提前致谢!

推荐答案

问题不在用于单击链接的代码中。它是在单击链接时执行的JavaScript中。 JavaScript是错误的,或者HtmlUnit使用的JavaScript解释器在运行时遇到问题。

The problem is not in the code used to click on the link. It's in the JavaScript executed when the link is clicked. Either the JavaScript is buggy, or the JavaScript interpreter used by HtmlUnit has a problem running it.

问题似乎是参数x在执行期间具有无穷大值。

The problem seems to be with a parameter x which has the Infinity value during the execution.

这篇关于努力点击htmlunit内的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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