How to check URL for 404 using Selenium WebDriver?

前端 未结 6 1823
时光说笑
时光说笑 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:21

    Try this:

    List allImages = driver.findElements(By.tagName("img"));
    for (WebElement image : allImages) {
      boolean loaded = ((JavaScriptExecutor) driver).executeScript(
          "return arguments[0].complete", image);
      if (!loaded) {
        // Your error handling here.
      }
    }
    

提交回复
热议问题