Selenium 中有哪些不同型別的等待可用?
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();
// pause the execution 1 seconds
Thread.sleep(1000);
long startaftersleep = System.currentTimeMillis();
System.out.println("Sleep time in ms = "+ startaftersleep - start);
}
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP