How to check URL for 404 using Selenium WebDriver?

前端 未结 6 1868
时光说笑
时光说笑 2021-02-01 20:44

What is the most convenient way using Selenium WebDriver to check if an URL GET returns successfully (HTTP 200)?

In this particular case I\'m most interested in verifyin

6条回答
  •  情书的邮戳
    2021-02-01 21:20

    Funda for Checking 404:

    Basically 404s can be checked via HTTP Response of the URL.

    Step 1: Import the Library for HTTPTestAPI
    Step 2: Create the HTTPRequest.

    String URL="www.abc.com";
    HTTPRequest request = new HTTPRequest(URL);
    
    //Get the response code of the URL
    int response_code = request.getResponseCode();
    
    //Check for 404:
    if(response_code == 404)
        FAIL -- THE URL is leading to 404.
    else
        PASS
    

提交回复
热议问题