Android espresso-web等待网页元素方法

xiaoxiao2021-02-28  84

//方法中只允许传xpath,只要稍作修改就可以以其他的定位方式来操作  public static boolean waitForWebView(String xpath) {                 long endtime_2 = SystemClock.uptimeMillis() + 10000;         do {             try {                 Web.onWebView().forceJavascriptEnabled();                 Web.onWebView().withElement(DriverAtoms.findElement(Locator.XPATH, xpath));                 return true;             } catch (Throwable e) {                 if (!e.getMessage().equals("java.lang.RuntimeException: Atom evaluation returned null!")) {                     throw new RuntimeException("Util.waitForWebView()抛出异常:" + e.getMessage());                 }             }             if (SystemClock.uptimeMillis() > endtime_2) {                 return false;             }         } while (true);     }

转载请注明原文地址: https://www.6miu.com/read-78582.html

最新回复(0)