Selenium有哪些不同的等待类型?
隐式等待
这是Selenium中动态等待的一种,其语法为-
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
明确等待
这是Selenium中动态等待的一种,其语法为-
WebDriverWait w = new WebDriverWait(driver,);
w.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("<<xpath expression>>")));流利的等待
这是Selenium中动态等待的一种,其语法为-
Wait<WebDriver> w = new FluentWait<WebDriver>(driver).withTimeout(Duration.ofSeconds(30)) .pollingEvery(Duration.ofSeconds(3)).ignoring(NoSuchElementException.class);
静态等待
这用于将执行暂停指定的时间。
示例
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
import java.util.List;
public class ThreadWait {
public static void main(String[] args) throws InterruptedException {
long start = System.currentTimeMillis();
//暂停执行1秒
Thread.sleep(1000);
long startaftersleep = System.currentTimeMillis();
System.out.println("Sleep time in ms = "+ startaftersleep - start);
}
}热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短