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
.