How to find an element that contains specific text in Selenium WebDriver with Python?

Sometimes, we want to find an element that contains specific text in Selenium WebDriver with Python.

In this article, we’ll look at how to find an element that contains specific text in Selenium WebDriver with Python.

How to find an element that contains specific text in Selenium WebDriver with Python?

To find an element that contains specific text in Selenium WebDriver with Python, we can use the find_elements_by_xpath method.

For instance, we write

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

to call find_elements_by_xpath with "//*[contains(text(), 'My Button')]" to find the elements that has text My Button.

Conclusion

To find an element that contains specific text in Selenium WebDriver with Python, we can use the find_elements_by_xpath method.