使用场景:在某些加载或者是需要一些耗时的操作之后才能获取到的控件
python:
def wait_element(driver, time, element_by, element, msg):
"""
等待元素出现
:param driver: driver
:param time: 等待时间
:param element_by: 元素类型
:param element: 元素关键字
:param msg: 输出信息
:return:
"""
WebDriverWait(driver, time).\
until(expected_conditions.presence_of_element_located((element_by, element)),msg)
#调用
wait_element(self.deriver, 10, By.ID, "com.xxx.xxx.ceshi:id/main_select_index_rb", "没有发现xxxx...")
java:
public boolean waitForAeTextAppear(String text, int timeOutInSeconds) {
try {
WebDriverWait wait = new WebDriverWait(mDriver, timeOutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(String.format("//*[@text='%s']", text))));
return true;
} catch (Exception e) {
return false;
}
}
这里随便写了下,具体的一些使用场景还需自行封装
参考:https://testerhome.com/topics/13620
https://blog.youkuaiyun.com/meyoung01/article/details/43056069