How do I find an element that contains specific text in Selenium Webdriver (Python)?
To locate an element, you need to find the element based on its XPath as you can specify the text the element should contain using "contains(text(), 'YOUR TEXT HERE')".
element = self.driver.find_element_by_xpath("//*[contains(text(), 'Wikipedia')]")
To locate the element based on whether any of its children contain the correct text use "contains(., 'YOUR TEXT HERE')" instead.
element2 = self.driver.find_element_by_xpath("//*[contains(., 'Wikipedia')]")
Leave a reply
Your email address will not be published. Required fields are marked*