3

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. "

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()

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

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.

So confused..please help :-)

Thanks in advance!

Lostsoul
  • 25,013
  • 48
  • 144
  • 239

1 Answers1

1

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.

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

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Thats not good. Am I totally out of luck or is there something else I can do? I have done alot of work and its bad that the next page click can kill this project. Is there a way to make the javascript behave better? or some setting to let htmlunit's javascript interpreter behave better? or even load another javascript engine in it(google's v8, mozilla spidermonkey,etc..) – Lostsoul Mar 09 '11 at 17:40
  • 1
    I FIGURED IT OUT!! YAY. I was worried my project would fail but basically I had to set webclient = WebClient(BrowserVersion.FIREFOX_3_6) I set it to IE7 before and it wasn't working. I guess the site behaves differently with different browser heading.. – Lostsoul Mar 09 '11 at 18:02