【发布时间】:2019-04-08 11:15:06
【问题描述】:
您好,我正在尝试在 Java 中的 selenium webdriver 中单击带有文本“€11”的特定按钮。
按钮位于此格式中,页面上还有另一个按钮,代码完全相同,但价格不同:
<button type="button" class="bui-button bui-spacer--medium bui-button--primary bui-button--wide">
<span class="bui-button__text">€11</span>
</button>
我该怎么做。任何帮助表示赞赏:)
【问题讨论】:
-
实际上,span 是您的按钮。最简单的方法(如果我没记错的话)向 span 添加一个 id 并使用它点击
-
使用
driver.findElement(By.cssSelector("button[type='button']>span[class='bui-button__text']")).click();告诉我 -
你也可以使用 driver.findElement(By.xpath("//span[@class='bui-button__text']")).click();
-
作为 ...页面上还有另一个按钮,其代码完全相同,但价格不同...您需要使用更多信息来更新问题outerHTML,所以我们可以区分这两个按钮。
-
添加图片@DebanjanB
标签: java css selenium selenium-webdriver qwebelement