TestProject Forum
Powered by leading experts in the test automation community

Find an element that contains specific text with Selenium in Python

I want to be able to search for elements based on text “button”

driver.find_elements_by_xpath('//div[contains(text(), "button")]')

I tried xpath/css but nothing seems to work

Try this:

driver.find_elements_by_xpath("//*[contains(text(), 'button')]")

Use the asterisk character * to find any/all elements that answer such criteria