charlie
charlie

Reputation: 77

HtmlUnit - ElementNotFound Exception

I'm using HtmlUnit [see Testing a website using C# ], 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?

Upvotes: 1

Views: 434

Answers (2)

Mohamed FadlAllah
Mohamed FadlAllah

Reputation: 39

this is equal to when you click a button on web page using Web Browser, and because of slow internet connection it will not respond, so you need to reload the page again and so you must do the same in your code handle reloading page again when this exception thrown.

Upvotes: 2

Rodney Gitzel
Rodney Gitzel

Reputation: 2710

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.

Upvotes: 0

Related Questions