Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

With Selenium IDE, how can I test if an element's inner text contains a specific string? For example:

<p id="fred">abcde</p>

'id=fred' contains "bcd" = true)

1 Answer

0 votes
by (62.9k points)

Selenium web driver is one of the most standard tool utilized in IT business. typically in automation testing, tester need to deal with text on web page. There are numerous ways to examine text is present or not on web page. some of the ways are listed below

1. If tester wants to check text on whole page then use :

a. By using getPageSource()

if (webDriver.getPageSource().contains("Expected text")) 

b. By XPAth

if(isDisplayed(By.xpath("//*[text()='Expected text']")))

public mathematician isDisplayed(By by) catch (NoSuchElementException e) 

}

2. If tester wants to check text of explicit element :

if(webDriver.findElement(By.cssSelector("")).getText().equalsIgnoreCase(""))

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s automation testing course

Browse Categories

...