Java:HTMLUnit - 单击Javascript按钮

时间:2022-06-11 15:42:31

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:

我遇到了以下问题:我为一些网站编写了一个自动测试系统。现在我遇到的问题是我必须在测试用例中按某个特定按钮。不幸的是,按钮不是普通按钮。我认为他背后有一些javascript函数。它是这样给出的:

<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

我也得到了很多jquery错误,但我用它们压抑了它们

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.

现在我的问题:由于javascript错误,我的代码是否真的有效或无法正常工作?谢谢您的帮助。

Best Regards,

1 个解决方案

#1


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

这可能是HtmlUnit的问题,请提供完整的案例进行检查。另外,请确保使用最新版本2.16。

#1


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

这可能是HtmlUnit的问题,请提供完整的案例进行检查。另外,请确保使用最新版本2.16。