如何使用webdriver查找按钮元素? [英] How to find button element with webdriver?
本文介绍了如何使用webdriver查找按钮元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为按钮添加了以下代码:
I have the following code for a button :
<div class="buttons">
<button class="btn dialog-confirm btn-primary" style="margin-left: 4px;">Confirm</button>
<button class="btn dialog-cancel" style="margin-left: 4px;">Cancel</button>
</div>
有两个按钮是确认",另一个是取消"我可以使用XPath找到该按钮,但是我不想使用XPath.在这种情况下,还有其他方法可以找到按钮元素吗?
There are two buttons on is Confirm and another is Cancel I can find the button with XPath but I don't want to use XPath. Is there another way to find the button element in this case?
我尝试过:
driver.findElement(By.className("btn dialog-confirm btn-primary")).click();
找不到按钮谢谢您的帮助
It did not find the button Thank you for your help
推荐答案
只需检查一个 dialog-confirm
类:
driver.findElement(By.className("dialog-confirm")).click();
或者,使用 CSS选择器
:
Or, use a CSS Selector
:
driver.findElement(By.cssSelector("button.dialog-confirm")).click()
这篇关于如何使用webdriver查找按钮元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文