1.基类中编写隐式等待方法
- locaor为定位元素
- timeout为查找元素等待时间
public AndroidElement waitforelement(By locaor, int timeout ) { AndroidElement element =null; try { System.out.println("最长等待"+timeout+"秒"); //设置显示等待 WebDriverWait wait = new WebDriverWait(driver,timeout); element =(AndroidElement)wait.until(ExpectedConditions.visibilityOfElementLocated(locaor)); } catch (Exception e) { System.out.println(locaor+"元素没有在页面出现"); } return element; }
2.其它类中调用隐式等待方法查找元素
@Test public void login() throws Exception { waitforelement(By.id("元素ID值"),60).click();//60可更改为各个数字,视元素加载速度自定义
}
3.运行login测试用例,可点击相应元素,成功!!