This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

I am using two different version of iOS for testing my mobile application.

Xpath of an element varies for both the application

Is it possible to use two @iOSFindBy for the element?

Example
@iOSFindBy(xpath="//[@name=‘Login’]")
@iOSFindBy(xpath="//[@name=‘SignIn’]")
protected WebElement loginbtn;

Based on the version and availabilty of xpath will it automatically fetch the element ?

  • created

    Jan '19
  • last reply

    Jan '19
  • 1

    reply

  • 234

    views

  • 2

    users

  • 1

    link

Yes, it’s possible to, you need to use HowToUseLocators annotation with LocatorStrategy.ALL_POSSIBLE which means either Login OR SignIn

@HowToUseLocators(iOSXCUITAutomation = LocatorGroupStrategy.ALL_POSSIBLE)
@iOSXCUITFindBy(xpath="//[@name=‘Login’]")
@iOSXCUITFindBy(xpath="//[@name=‘SignIn’])
protected WebElement loginbtn;

The problem in using 2 locator strategy is it will make execution slow. Instead of that you can use NS Predicate, it would be faster as compared to earlier one

@iOSXCUITFindBy(iOSNsPredicate = “name == ‘Login’ OR name == ‘SignIn’”)
protected WebElement loginbtn;

For more info on predicate string https://github.com/facebook/WebDriverAgent/wiki/Predicate-Queries-Construction-Rules1