IFM2
IFM2

Reputation: 29

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:

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

Upvotes: 1

Views: 97

Answers (2)

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

Upvotes: 2

Keliggg
Keliggg

Reputation: 131

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()

Upvotes: 2

Related Questions