强制等待、隐式等待、显示等待。

1.强制等待:线程等待即:Thread.sleep(2000);

2.显示等待:比较智能,找到页面元素就继续执行否则会继续等待(在设置好的等待时间内),如果在设置的等待时间内还没找到也会报出元素定位不到。

写法一:WebDriverWait wait= new WebDriverWait(driver, 10);
              wait.until(ExpectedConditions.presenceOfElementLocated(By.id("js-signin-btn")));

写法二:

WebElement wait= new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.id("js-signin-btn")));

3.隐试等待:全局的等待10秒钟

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

原文地址:https://www.cnblogs.com/wangffeng293/p/13834610.html