find an element that contains specific text with Selenium in Python

  • 1 Replies
  • 5688 Views
I want to be able to search for elements based on text "button"

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

I tried xpath/css but nothing seems to work

*

Ruhit

  • *
  • 22
Try this:

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

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

 

Sitemap 1 2 3 4 5 6 7 8