[英]I cant click in a button and selenium not finding element selenium python
I want the bot to click on Ya, Benar I tried this but it didn't work for me:我希望机器人点击 Ya, Benar 我试过这个,但它对我不起作用:
driver.find_elements_by_xpath("//*[contains(text(), 'Ya, Benar')]").click()
If you want to user find_elements_by_xpath
procede like this:如果你想用户
find_elements_by_xpath
像这样进行:
buttons = driver.find_elements_by_xpath("//*[contains(text(), 'Ya, Benar')]")
for btn in buttons:
btn.click()
it means that find_elements_by_xpath
returns an array这意味着
find_elements_by_xpath
返回一个数组
Be careful you use a method that returns a list of elements.请小心使用返回元素列表的方法。 To click on an element you have to select it and only it
要单击一个元素,您必须选择它并且只选择它
You choose the element in the list for example 0您选择列表中的元素,例如 0
driver.find_elements_by_xpath("//*[contains(text(), 'Ya, Benar')]")[0].click()
Or use the method that returns the first element (w/os)或者使用返回第一个元素的方法(w/os)
driver.find_element_by_xpath("//*[contains(text(), 'Ya, Benar')]").click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.