Java client 5.0.1: LocatorGroupStrategy.ALL_POSSIBLE not working for iOSXCUITAutomation

Hi all,

I have an issue with PageObject fields for iOS. Back button on NavBar has different ID’s on different screens in our application under test, so I declared it this way:

    @HowToUseLocators(androidAutomation = LocatorGroupStrategy.ALL_POSSIBLE, 
                      iOSXCUITAutomation = LocatorGroupStrategy.ALL_POSSIBLE)
    @AndroidFindBy(xpath = "//android.widget.ImageButton[@content-desc='Navigate up']")
    @AndroidFindBy(xpath = "//android.widget.ImageButton[@content-desc='Collapse']")
    @iOSFindBy(accessibility = "Back")
    @iOSFindBy(accessibility = "back icon")
    public MobileElement btnBack;

However, the element cannot be found. The exception I get reads the following:

    Can't locate an element by this strategy: Locator map: 
    - native content: "By.chained({By.AccessibilityId: Back,By.AccessibilityId: back icon})" 
    - html content: "by id or name "btnBack""

Should it really be By.chained there? I thought it had to be By.all or something similar.
Element can be found is either of these locators is used separately without LocatorGroupStrategy specified.

For Android it works without any issues.
Java client version is 5.0.1.

@darina-techery not sure if it is an issue:
but when i use ONLY androidAutomation or ONLY iOSXCUITAutomation - i do not have such problem.

Also update “iOSFindBy” - > “iOSXCUITFindBy” - just better look :slight_smile:

in code:

    /**
     * @return the strategy which defines how to use locators which are described by
     * the {@link **iOSXCUITFindBy**} annotation. These annotations can define the chained searching
     * or the searching by all possible locators.
     */
    LocatorGroupStrategy iOSXCUITAutomation() default LocatorGroupStrategy.CHAIN;

so it is correct for you to use with “iOSFindBy”:

@HowToUseLocators(androidAutomation = LocatorGroupStrategy.ALL_POSSIBLE, 
                      iOSAutomation = LocatorGroupStrategy.ALL_POSSIBLE)

Am I right to suppose that both iOSFindBy and iOSXCUITFindBy are valid in case of
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
, but only iOSXCUITFindBy will be afffected by iOSXCUITAutomation() strategy?
I thought that iOSXCUITAutomation() is needed for XCUITest engine, and iOSAutomation() is for UIAutomator (or whatever it is called), that’s why I used that annotation and not another one.

UPD: iOSAutomation works for XCUITest as automationName and iOSFindBy as FindBy annotation, thank you!

@darina-techery they both valid. but in terms of your code you pointing to use “iOSXCUITAutomation” which is using “iOSXCUITFindBy” ONLY. So with “iOSFindBy” in your code you did not mention “iOSAutomation” which uses default “CHAIN” :slight_smile:

can anyone explain me the difference between All Possible and chain locator strategy.

My condition is that if once locator strategy fails then another should work for android.

@Prasad_Madge allPossible means the first found. Chain is first finding first locator then inside second and so on.

Hi Aleksei. I tried to use this LocatorGroupStrategy.ALL_POSSIBLE / CHAIN at the class level and also at the Field level, and when I run, its showing weird behavior. Also imported the right classes.

For eg: I specify as below:

@AndroidFindBy(xpath=“abc”)
Mobile Element login;

and when I ran, I get the same exception that it goes to the By.id !!!: No matter you change the locator inside the @AndroidFindBy, say @AndroidFindBy(uiAutomator= “xyz”), still I get the same below exception which says that the ‘id’ is not present…

Exception I get
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of Located by By.id:

I am using Appium Java client v7.6.0 and Selenium v3.141.59. Please let me know if there is something I am missing?

This is not valid code. Write your code. Explain what element you need find. And we can help you.
PS with Android in most cases you do not need check visibility as far as only visible elements available in most cases.

Thanks for your assistance Aleksei. It was my mistake. After passing the appropriate driver to the pagefactory, all worked well…