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
5,776 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);

    }
}
answered Jul 18, 2019 by Abha
• 27,930 points
0 votes
For this type of message that gets disappear after sometime i would suggest you to check this post. i think this will 100% solve your problem


https://seleniumeasytutorials.blogspot.com/2020/05/how-to-verify-success-message-or.html?m=1
answered May 31 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,510 points
3,554 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31 in Selenium by Sri
• 2,970 points
4,563 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,890 points
2,611 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 2 in Selenium by Sri
• 2,970 points
2,894 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
• 27,930 points
1,430 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, 2019 in Selenium by Abha
• 27,930 points
2,375 views