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 教师闺蜜祝福语简短