aronsimt
aronsimt

Reputation: 25

Selenium python how to find button by full match

this (Selenium python) function clicking on Follow buttons, but also clicking on Following buttons (because Following also contains Follow). How to prevent it? I need full match (Follow only). thank you

buttons = driver.find_elements_by_xpath("//button[contains(.,'Follow')]")

Upvotes: 1

Views: 47

Answers (1)

KunduK
KunduK

Reputation: 33384

Try below xpath.The first one give you exact match and then second one truncate the space if they have.

//button[text()='Follow']

OR

//button[normalize-space(.)='Follow']

Code:

buttons = driver.find_elements_by_xpath("//button[text()='Follow']")

Upvotes: 1

Related Questions