How to check URL for 404 using Selenium WebDriver?

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

    Instead of traversing in Java, it may be faster to call javascript only once for all images.

    boolean allImgLoaded = (Boolean)((JavascriptExecutor) driver).executeScript(
        "return Array.prototype.slice.call(document.images).every(" 
        + "function (img) {return img.complete && img.naturalWidth > 0;});");
    

提交回复
热议问题