How Appium waiting to load elements

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/hsj880921/article/details/43056069
not say, directly on the code:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.concurrent.TimeUnit;

/**
* Created by Administrator on 2015/1/23.
*/
public class TaquTools {

<pre name="code" class="java"> /**
* 等待元素加载
*
* @param driver driver
* @param by 定位方式
* @param waitTime 等待时间
*/
public static void waitForVisible(WebDriver driver, final By by, int waitTime) {
WebDriverWait wait = new WebDriverWait(driver, waitTime);
for (int attempt = 0; attempt < waitTime; attempt++) {
try {
driver.findElement(by);
break;
} catch (Exception e) {
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
}
}
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
}

 

Use:
TaquTools.waitForVisible (Driver, By.id ( "tvEntranceOne"), 5); // wait for an element to load, 5S failed to load into a timeout

This same method is also available in WebDriver

Guess you like

Origin www.cnblogs.com/D-zsd/p/11302097.html