Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Verify/checking Text on page in Selenium


  • Testing a web application, we should to verify that elements are displaying correct values
    or text on the page
  • we will retrieve and verify text from an element by using the WebElement class'
    getText() method.
 Sample code as below: 
 
public void WebElementText()
{
//Get the message Element
WebElement message = driver.findElement(By.id("text"));
//Get the message elements text
String messageText = message.getText();
//Verify message element's text displays "Click on me and my
//color will change"
assertEquals("Click on me and my color will change",
messageText);
//Get the area Element
WebElement area = driver.findElement(By.id("area"));
//Verify area element's text displays "Div's Text\nSpan's Text"
assertEquals("Div's Text\nSpan's Text",area.getText());
}

Post a Comment

0 Comments