12

I'm using Selenium and JUnit with Java and I want to know if a 404 error occurs when opening a new popup by clicking on a link (i'm searching for a thing like assertTrue(selenium.no404error()).

How can I do that ?

LaurentG
  • 9,745
  • 8
  • 44
  • 61
user2572022
  • 121
  • 1
  • 1
  • 3

1 Answers1

19

You can't test if the HTTP status code is 404. This is explained in this other thread. The only way is to test for something in the page which can only be in your 404 error page. For instance:

assertTrue(driver.getTitle().contains("404"));

If you're not sure that your page contains something specific like 404 or Page not found. You could generate from the server a special tag code (e.g. a <meta> tag in the <head> section) and test for it with the WebDriver.

Community
  • 1
  • 1
LaurentG
  • 9,745
  • 8
  • 44
  • 61