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

来源:互联网 发布:印度it为何这么强 知乎 编辑:程序博客网 时间:2024/06/05 21:06
//方法中只允许传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);
    }
原创粉丝点击