Search code examples
seleniumappium-androidfindby

How to find elements with @FindBy if they have multiple id values


What I need is to declare page elements (mobile elements, with @FindBy or @AndroidFindBy) with two possible ids that will change depending on the version of the app that is being tested - we will have one id for the staging version and one for production and they will slightly different (one will have "debug" in the middle of the id value, and the other won't)

Is this possible (by using OR or any other way) and how?

Thank you.


Solution

  • You can use the annotation @FindAll. Here is the example:

    @FindAll({
            @FindBy(id = "one_id"),
            @FindBy(id = "another_id")
    })
    WebElement myElement;
    
    

    See the docs.

    The advantage of this approach is that you can actually combine the locators of different types.