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, 2019 in Selenium by Hansraj
17,300 views

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

    }
}

For further understanding, you can refer to the Selenium Course.

answered Jul 19, 2019 by Abha
• 28,140 points
0 votes
We can verify error messages on a webpage using Selenium webdriver using the Assertion.
answered May 31, 2020 by divyang
• 140 points

Related Questions In Selenium

–1 vote
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

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,500 points
13,763 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,184 views
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,910 points
7,258 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,895 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, 2019 in Selenium by Abha
• 28,140 points
6,084 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 3, 2019 in Selenium by Abha
• 28,140 points
9,586 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP