How to verify Error Message in Selenium Webdriver using Assert

Hello Welcome to Selenium tutorial, in this post we will see how to verify Error Message in Selenium.

Testing is nothing but verification and validation. Mostly in testing we verify title, some error messages , tooltip messages and so on.

To capture error message or simple text as well we can use predefined method called  getText().

getText() method will simply capture the error message or text and will return you a String then you can store in String variable and you can use in other application or you can verify as well.


Please refer below youtube video for the same.




Program for Verify  Error Message in Selenium Webdriver


Capture Error Message in Selenium
You can use getText() method for capturing simple text messages as well and using above method we can verify the same.

Note- If text does not match then TestNG will throw AssertionError and if we do not use Exception handling then it will simply terminate our application/ program.

For complete info visit TestNG Official site

Thanks for visiting my blog. Please comment if you finding any issue. Keep visiting.

Have a nice day 🙂


  1. Ashrita
  2. megha
  3. Gaurav Khurana
  4. ranjit
  5. Piyush Sharma
  6. Piyush Sharma
      • Nitin