一个selenium等待元素加载的类

xiaoxiao2021-02-28  45

import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; /** * 等待元素加载 * * * */ public class Wait { private WebDriver driver; public Wait(WebDriver driver){ this.driver = driver; PageFactory.initElements(driver, this); } //10秒内每500ms检查一次元素是否显示,超时则报异常 public void waitForElementPresent(String locator){ (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath(locator))); } //10秒内每500ms检查一次元素是否可用,超时则报异常 public void waitForElementIsEnable(String locator){ (new WebDriverWait(driver, 10)).until(ExpectedConditions.elementToBeClickable(By.xpath(locator))); } //等待timeout时间 public void watiFor(long timeout){ try{ Thread.sleep(timeout); } catch (InterruptedException e) { e.printStackTrace(); } } }
转载请注明原文地址: https://www.6miu.com/read-2613022.html

最新回复(0)