等待元素可用于Apache Cordova Webview驱动的应用程序的Java包装程序方法 [英] Java Wrapper method for waiting for element to be available for Apache Cordova Webview driven App

查看:66
本文介绍了等待元素可用于Apache Cordova Webview驱动的应用程序的Java包装程序方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于基于多个Webview的移动应用程序(使用Cordova,PhoneGap,XCode构建的iOS应用程序),我创建了以下方法来检查元素是否存在.请提示下面的代码段是否有意义?因为基于传统显式等待的传统包装器功能无法可靠地工作.

For Multiple Webview based Mobile App (iOS app built using Cordova, PhoneGap, XCode), I have created below method to check if element is present. Kindly suggest if below snippet makes sense? as traditional wrapper functions based on traditional Explicit waits are not working reliably.

    public boolean waitForElemToBeAvailable(final By by, final int timeout, int retries) {
    WebDriverWait wait = new WebDriverWait(appiumDriver, timeout);
    boolean success = false;
    final long waitSlice = timeout/retries;

    if(retries>0){
        List<WebElement> elements = appiumDriver.findElements(by);
        if(elements.size()>0){
            success = true;
            return success;
        }else {
            appiumDriver.manage().timeouts().implicitlyWait(waitSlice, TimeUnit.SECONDS);
            retries--;
        }
    }
    return success;
}

谢谢

推荐答案

根据您共享的代码块,我看不到通过implicitlyWait检查是否存在元素的任何附加值. .该实现看起来像是纯开销.相反,如果您查看Java文档 org.openqa.selenium.support.ui 包中的.html"rel =" nofollow noreferrer> ExpectedCondition 接口,该接口可对条件进行建模,该条件可能会被评估为不会null或false还包含 ExpectedConditions 可以由

As per the code block you have shared I don't see any value addition to check if element is present through implicitlyWait. The implementation looks as a pure overhead. Instead if you look into the Java Docs of ExpectedCondition Interface from the org.openqa.selenium.support.ui package which models a condition that might be expected to evaluate to something that is not null nor false also contains the ExpectedConditions Class that can be called in a loop by the WebDriverWait Class and the methods provides more granular approach to confirm if a particular condition have achieved or not. This gives us much more flexibility in choosing the desired behavior of a WebElement. Some of the widely used methods are :

  • 元素的存在:

  • Presence of an element :

presenceOfElementLocated(By locator)

  • 元素的可见性:

  • Visibility of an element :

    visibilityOfElementLocated(By locator)
    

  • 元素的交互性:

  • Interactibility of an element :

    elementToBeClickable(By locator)
    

  • 注意:根据文档请勿混合使用隐式等待和显式等待.这样做可能导致无法预测的等待时间.

    Note : As per the documentation Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times.

    这篇关于等待元素可用于Apache Cordova Webview驱动的应用程序的Java包装程序方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆