我有这个密码
driver.implicitly_wait(300) #I have tried different timers
driver.find_element_by_xpath("(//button[@aria-pressed='false'])[1]").click()
但是我得到了这个错误
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"(//button[@aria-pressed='false'])[1]"}
然而,这存在于我的HTML中
<div class="webix_el_box" style="width:90px; height:26px">
<button aria-pressed="false" type="button" class="webix_img_btn" style="line-height:22px;">
<span class="webix_icon_btn fa-lock red" style="max-width:22px;">
</span> Read Only
</button>
</div>
我还尝试使用xpath
//button[@class='webix_img_btn']//child::span[@class='webix_icon_btn fa-lock red']
这两种xpath在Google Chrome中都运行良好 在网站中,我可以使用Ctrl+F和“只读”找到按钮,我可以在Selenium中使用它吗
编辑:由于Selenium Driver is one page behind ajax call after large json data download而无法工作
要单击文本为只读的元素,必须为
element_to_be_clickable()
归纳WebDriverWait,并且可以使用以下Locator Strategies之一:使用
CSS_SELECTOR
:使用
XPATH
:注意:您必须添加以下导入:
参考资料
你可以在以下网站上找到关于NoSuchElementException的一些相关讨论:
试着去做
这将单击满足要求的第一个元素
相关问题 更多 >
编程相关推荐