【发布时间】:2016-02-19 10:17:16
【问题描述】:
我正在尝试使用 Selenium 单击按钮。
下面是代码
<div class="ui-dialog-buttonset">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button" aria-disabled="false">
<span class="ui-button-text"> … </span>
</button>
我尝试通过 css 选择器来做到这一点:
clickbutton=driver.find_element_by_css_selector("button.ui-button.ui-widget.ui-state-default.ui-corner-all.ui-button-text-only")
**我的错误:无法定位元素:{方法:“css选择器”,“选择器”:“button.ui-button.ui-widget.ui-state-default.ui-corner-all.ui-仅按钮文本"} **
我是不是搞错了?我不理解错误。我应该使用另一个定位器吗?
【问题讨论】:
-
您真的需要针对所有这些类吗?如果你这样做
ui-dialog-buttonset button.ui-button -
当我尝试这些时仍然不起作用
-
这些按钮不止一个吗?或者您是否尝试过使用
find_element_by_class_name? -
有 2 个按钮,一个“创建”按钮(我试图单击的按钮)和一个关闭按钮。我试过 driver.find_element_by_class_name ("ui-dialog_buttonset")
-
我明白了。你知道 xpath 吗?
标签: css python-2.7 unit-testing selenium