Example of verifyTextPresent in Webdriver

Here is another example which takes in a WebElement and searches the text of elements with particular tags

public boolean verifyTextPresent(WebElement rootElement, String tag, String text) {
List elements = rootElement.findElements(By.tagName(tag));
boolean match = false;
for (WebElement elem : elements){
String elementText = elem.getText();
if (elementText.contains(text)){
match = true;
break;
}
}
try {
Assert.assertTrue(match);
System.out.println("\"" + text + "\" was found within elements within the passed in WebElement with ID (" + rootElement.getAttribute("id")+ ")");
}
catch (Exception e) {
System.err.println("\"" + text + "\" not found within elements within the passed in WebElement with ID (" + rootElement.getAttribute("id")+ ")");
}
return match;
}

Submitted By: Daniel

Using verifyTextPresent in Selenium 2 Webdriver

There is no verifyTextPresent in Selenium 2 Webdriver; I have created a function that you use to verify if a particular text is present on a web page. You can change the name of the function to anything you want.
public void verifyTextPresent(String value)
{
driver.PageSource.Contains(value); ;
}

Using the function in your test script.

try
{
Assert.IsTrue(verifyTextPresent("Selenium Wiki"));
Console.WriteLine("Selenium Wiki test is present on the home page");
}
catch (Exception)
{
Console.WriteLine("Selenium Wiki test is not present on the home page");
}

If you found this solution helpful or have something extra to add, feel free to share it here by commenting below.