views:

26

answers:

1

I'm using HtmlUnit [see this], and I bumped into a weird problem:
I'm trying to call a page, click a button and retrieve the subsequent page. It works fine, but sometimes it bumps out with ElementNotFoundException when I try setting the value attribute for a field in the retrieved page.

I tried adding a Sleep(1000), but it doesn't help...

Any idea?

A: 

Try adding a catch of ElementNotFoundException and do a print of page.toXml() out to the console when it happens. Chances are you are not getting the page you think you are getting.

Rodney Gitzel
I noticed that I'm getting this exception only when I have a weak internet connection. Once it is strong it works fine. It seems that HtmlUnit has some TimeOut, and when it expires he just returns a Null object....
charlie
That could well be: http://htmlunit.sourceforge.net/apidocs/com/gargoylesoftware/htmlunit/WebClient.html#getTimeout%28%29
Rodney Gitzel