[英]Getting Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="None"]"} Python when using selenium
[英]Python: Selenium no such element: Unable to locate element: {“method”:“xpath”,“selector”:“//button[@data-id=1]”}
为什么我得到这个错误no such element: Unable to locate element: {"method":"xpath","selector":"//button[@data-id=1]"}
测试.py
zone = Zone.objects.last()
self.browser.refresh()
time.sleep(2)
self.browser.find_element_by_xpath("//button[@data-id="+str(zone.id)+"]").click() # zone.id = 1
我也试过self.browser.find_element_by_id('update_id_'+str(zone.id))但不工作:(怎么了?html
<button type="button" id="updateButton update_id_2" class="btn btn-xs btn-primary updateButton" data-id="2">
<i class="fa fa-edit"></i>
</button>
从错误消息和 Button 的代码中,我可以看到zone.id
值出错了。 zone.id
的值是 1 而不是 2。
您可以尝试使用,
self.browser.find_element_by_css_selector('.btn.btn-xs.btn-primary.updateButton').click()
或者
self.browser.find_element_by_id('updateButton update_id_2').click()
如果您可以提供更多 HTML 代码,我可以使用find_element_by_xpath
为您提供上述实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.