1. 设置显示等待
Java代码:
1
2
3
4
5
|
public static WebElement WaitForElement(WebDriver driver, String locator) { WebElement targetElement = ( new WebDriverWait(driver, 10 )).until(ExpectedConditions.presenceOfElementLocated(By.xpath(locator))); return targetElement; } |
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
2. 设置隐式等待
Java代码:
1
2
3
4
|
WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait( 10 , TimeUnit.SECONDS); WebElement myDynamicElement = driver.findElement(By.id( "xxxx" )); |