How can I verify Error Message on a webpage using Selenium Webdriver?

0 votes
How can I verify Error Message on a webpage using Selenium Webdriver?
Jul 18 in Selenium by Hansraj
63 views

1 answer to this question.

0 votes

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);

    }
}
answered Jul 18 by Abha
• 24,440 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
762 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,002 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
714 views
0 votes
1 answer

How can I get meta-description of a webpage using Selenium Webdriver?

Hey Sonal, to get the meta-description of ...READ MORE

answered Jul 23 in Selenium by Abha
• 24,440 points
126 views
0 votes
1 answer

How can I send some data to a Prompt Alert box using Selenium Webdriver?

Hey Abhishek, you can use sendKeys() method ...READ MORE

answered Jul 2 in Selenium by Abha
• 24,440 points
70 views