Htmlunit - 找不到按钮
Htmlunit - Button cannot be found
我想点击带有此代码的按钮(“...”表示复制太长):
<a title="theTitle" id="123654" onclick="..." >Press me!</a>
使用 Htmlunit。我的代码是:
try (final WebClient webClient = new WebClient()) {
final HtmlPage page = webClient.getPage("http://pathToURL.html");
HtmlButton button = (HtmlButton) page.getElementById("123654");
System.out.println(button);
}
问题是按钮为空。代码有什么问题?
谢谢。
来自API docs:
public class HtmlButton extends HtmlElement
implements DisabledElement, SubmittableElement, FormFieldWithNameHistory Wrapper
for the HTML element "button".
<a>
不是按钮,因此您的程序找不到它。
你想为此使用 HtmlAnchor
。
public class HtmlAnchor extends HtmlElement
Wrapper for the HTML
element "a".
我想点击带有此代码的按钮(“...”表示复制太长):
<a title="theTitle" id="123654" onclick="..." >Press me!</a>
使用 Htmlunit。我的代码是:
try (final WebClient webClient = new WebClient()) {
final HtmlPage page = webClient.getPage("http://pathToURL.html");
HtmlButton button = (HtmlButton) page.getElementById("123654");
System.out.println(button);
}
问题是按钮为空。代码有什么问题?
谢谢。
来自API docs:
public class HtmlButton extends HtmlElement
implements DisabledElement, SubmittableElement, FormFieldWithNameHistory Wrapperfor the HTML element "button".
<a>
不是按钮,因此您的程序找不到它。
你想为此使用 HtmlAnchor
。
public class HtmlAnchor extends HtmlElement
Wrapper for the HTML element "a".