简体   繁体   English

如何单击没有ID名称的按钮

[英]How to Click Button With out ID name

I am using Htmlunit and need to click on a button that doesn't have an ID to reference it. 我正在使用Htmlunit,需要单击没有ID的按钮来引用它。 It is a Log In button that I need to click on. 我需要单击“登录”按钮。 After inspecting the button, the information for it is: 检查按钮后,其信息为:

<button type="submit" class="button-standard button-primary" tabindex="4">
<span class="button-standard-text">Log In</span>
</button>

How could I reference this button using Htmlunit? 如何使用Htmlunit引用此按钮?

I have referred to this post , but can't seem to get it working: 我已经提到了这篇文章 ,但似乎无法使其正常工作:

Unless you have another Log In button inside a span, inside a button that happens to perform a different logic (very unlikely), this should do the trick: 除非跨度内的另一个Log In按钮,恰好执行不同逻辑的按钮内(非常不可能),否则应该做到这一点:

HtmlElement e = page.getFirstByXPath("//button[span[text()='Log In']]");
System.out.println(e.asXml());

Even if you have multiple buttons matching, you can continue filtering using the classes or a more complex XPath string that traverses the whole tree. 即使您有多个匹配的按钮,也可以使用这些类或遍历整个树的更复杂的XPath字符串继续进行过滤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM