简体   繁体   English

Python: Selenium 没有这样的元素: 无法定位元素: {“method”:“xpath”,“selector”:“//button[@data-id=1]”}

[英]Python: Selenium no such element: Unable to locate element: {“method”:“xpath”,“selector”:“//button[@data-id=1]”}

Why I got this error 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]"}

test.py测试.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

I have also tried with self.browser.find_element_by_id('update_id_'+str(zone.id)) but not working:( what's wrong going on? html我也试过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>

From the error message and the code for Button, I could see that zone.id value is coming wrong.从错误消息和 Button 的代码中,我可以看到zone.id值出错了。 The value of zone.id is coming as 1 instead of 2. zone.id的值是 1 而不是 2。

You can try using,您可以尝试使用,

self.browser.find_element_by_css_selector('.btn.btn-xs.btn-primary.updateButton').click()

or或者

self.browser.find_element_by_id('updateButton update_id_2').click()

If you can give bit more HTML code, I can give you the implementation of above using find_element_by_xpath .如果您可以提供更多 HTML 代码,我可以使用find_element_by_xpath为您提供上述实现。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到消息:没有这样的元素:无法找到元素:{&quot;method&quot;:&quot;css selector&quot;,&quot;selector&quot;:&quot;[id=&quot;None&quot;]&quot;} Python 使用 selenium 时 - Getting Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="None"]"} Python when using selenium 无法找到硒中的元素:{“方法”:“ css选择器”,“选择器”:“ [id =” identifierId”]”} - Unable to locate element: {“method”:“css selector”,“selector”:“[id=”identifierId“]”} in selenium 上传图像 Selenium Webdriver Python - 无法上传图像 =&gt; 错误:“无法定位元素:{“方法”:“xpath”,“选择器”:“” - Upload image Selenium Webdriver Python - Unable upload image => Error: "Unable to locate element: {"method":"xpath","selector":"" 无法定位元素:{"method":"xpath","selector":"//input[@id='fieldname3_1']"} - Unable to locate element: {"method":"xpath","selector":"//input[@id='fieldname3_1']"} 使用 Selenium Python 选择下拉菜单 - 无法定位元素:{“method”:“css selector”,“selector”:"[id= - Selecting drop-down using Selenium Python - Unable to locate element: {“method”:“css selector”,“selector”:"[id= NoSuchElementException:消息:没有这样的元素:无法找到元素:{"method":"xpath","selector":"//*[@id="my id"]"} - NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="my id"]"} 没有这样的元素:无法定位元素:{"method":"xpath","selector":"//*[@id="_id0:logon:USERNAME"]"} - no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="_id0:logon:USERNAME"]"} selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素:{&quot;method&quot;:&quot;xpath&quot;,&quot;selector&quot;:&quot;&quot;} - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":""} Python Selenium:无法通过Xpath定位元素 - Python Selenium: Unable to locate the element by Xpath 无法使用 xpath 使用 python 和 selenium 定位元素 - Unable to locate element with xpath using python and selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM