【发布时间】:2014-01-05 14:31:00
【问题描述】:
<input type="submit" class="submit-button" style="white-space:normal" value="hello world!">
这就是 HTML 提交按钮的工作方式,在 HTMLUNIT 中我已经得到了表单,使用列表:
HtmlForm form = this.page.getForms().get(0);
但现在我尝试加载的网站在提交按钮上没有 id 或名称,只有一个类和一个值。
我试过这样做:
HtmlButton button = (HtmlButton) page.getByXPath("/html/body//form//input[@type='submit' and @value='Hello world!']");
但是当它加载时,我得到这个错误:
Exception in thread "Thread-1" java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.gargoylesoftware.htmlunit.html.HtmlButton
at Web.getButton(Web.java:78)
at java.lang.Thread.run(Unknown Source)
如何获取没有 id 或 value 的按钮?
【问题讨论】: