How to find button with Selenium by its text inside (Python)?


I have the following three buttons that I can’t figure out how to grab the text that is inside of them (e.g Outliers). I tried browser.find_element_by_link_text("Outliers").click(), but got “Unable to locate element” error. How can I do it?

enter image description here


See: find_element_by_* commands are deprecated in selenium

In newer versions of selenium try:

from import By
browser.find_element(By.XPATH, '//button[text()="Outliers"]')

older versions of selenium:


To update ALL of the older versions I found a nifty regex here, and then just fixup the import:

Answered By – jmunsch

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published