简体   繁体   English

我无法单击按钮并且硒找不到元素硒python

[英]I cant click in a button and selenium not finding element selenium python

Web page inspect网页检查

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM