selenium 三大等待

三大等待方式

硬性等待

thread.sleep(3000)

隐式等待

        //隐式等待,超时等待5秒,全局有效
        webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

显示等待

       //显示等待,直到xpath元素出现,会接触等待
        WebDriverWait webDriverWait = new WebDriverWait(webDriver,3000);
        webDriverWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"11\"]/div/div/h3/a")));
        webDriver.findElement(By.xpath("//*[@id=\"11\"]/div/div/h3/a")).click();
posted @ 2022-07-20 22:48  小幼虫虫  阅读(28)  评论(0)    收藏  举报