Categories
Python Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *