Skip to content Skip to sidebar Skip to footer

How To Use "if" Operator For Appium Tests

I need to check if button with title 'title_I_need' exist. And if exist to press it if not press another one. All this stuff in javaScript. What I did I recorded in Appium.App test

Solution 1:

The easiest way to do this is to use findElementsBy (notice the s) which will return an array. Then simply check if the array is empty. Put this in a function and call it something like doesElementExists. A corresponding java method to this would be :

public boolean doesElementExists(By by) {
    try {
        List allElements = driver.findElements(by);
        if ((allElements == null) || (allElements.size() == 0))
            return false;
        else
            return true;
    } catch (java.util.NoSuchElementException e) {
        return false;
    }
}

Post a Comment for "How To Use "if" Operator For Appium Tests"