Search code examples
javascriptjquerybuttonhtmlunit

Java: HTMLUnit - Click on a Javascript Button


Good evening everyone,

I got the following problem: I programmed an automated test-system for some websites. Now I have the problem that I must press a specific button at some time in a test case. Unfortunately, the button isn't a normal button. I think that he got some javascript functions behind it. It's given like this:

<button class="btn">Login</button>

How can I solve this problem? I already tried it like this:

List<HtmlElement> elements1 = (List<HtmlElement>) 
page6.getByXPath("(//button)[1]");
HtmlElement element2 = elements1.get(0);
page6 = element2.click();

I also get a lot of jquery errors but I surpressed them with

this.webClient.getOptions().setThrowExceptionOnScriptError(false);

Now my question: Is my code actually working or doesn't it work due to the javascript errors? Thank you for your help.

Best Regards,


Solution

  • This could be an issue with HtmlUnit, please provide your complete case to check. Also, please make sure you use latest version 2.16.