How do I find an element that contains specific text in Selenium Webdriver (C#)?
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')".
IWebElement element = driver.FindElement(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.
IWebElement element2 = driver.FindElement(By.XPath("//*[contains(., 'Wikipedia')]"));
Leave a reply
Your email address will not be published. Required fields are marked*