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

Viewed 47

Web page inspect

I want the bot to click on Ya, Benar I tried this but it didn't work for me:

driver.find_elements_by_xpath("//*[contains(text(), 'Ya, Benar')]").click()
2 Answers

If you want to user find_elements_by_xpath procede like this:

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

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

driver.find_elements_by_xpath("//*[contains(text(), 'Ya, Benar')]")[0].click()

Or use the method that returns the first element (w/o s)

driver.find_element_by_xpath("//*[contains(text(), 'Ya, Benar')]").click()
Related