Hey Hansraj, to verify an error message on a webpage, you can use getText() and Assert method in Webdriver:
import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class TestNaukri {
@Test
public void TestError()
{
FirefoxDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.naukri.com/");
driver.findElement(By.id("p0submit")).click();
// This will capture error message
String actual_msg=driver.findElement(By.id("emailId_err")).getText();
// Store message in variable
String expect="plz enter valid email";
// Verify error message
Assert.assertEquals(actual_msg, expect);
}
}
For further understanding, you can refer to the Selenium Course.