Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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;
}

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
958 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...