Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catching a 404 error with Selenium [duplicate]

Tags:

java

selenium

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 ?

like image 705
user2572022 Avatar asked Jul 15 '13 14:07

user2572022


1 Answers

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.

like image 109
LaurentG Avatar answered Nov 05 '22 19:11

LaurentG