0

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.

Ritu pal
  • 306
  • 2
  • 11
Jess
  • 13
  • 1
  • 7

2 Answers2

3

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.

Alexey R.
  • 8,057
  • 2
  • 11
  • 27
  • 1
    Thank you, this way will be the easiest for our team to implement. Also, we have many elements found via AndroidFindBy, do they have a similar annotation? I can't seem to find anything in the docs – Jess Mar 06 '21 at 09:50
  • @Jess there seems to be the [exact alternative](https://appium.github.io/java-client/io/appium/java_client/pagefactory/AndroidFindAll.html) – Alexey R. Mar 06 '21 at 10:38
0

You might try with passing the following Xpath to @FindBy:

//*[@id='example-001' | @id='example-debug-001']
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
  • 1
    Thank you! I think that FindAll will require less refactoring for our team as we already have all those elements defined (both id versions), we just need to wrap them with FindAll now (see the answer above) – Jess Mar 04 '21 at 14:08