How to use PageFactory to locate android and iOS element using the same script

Hi All,

From the reffered discussions I have understood that that we can use page factory to call android and ios locators using:

@AndroidFindBy(…)
@IOSFindBy(…)
MobileElement ele;

But how am I supposed to tell page factory which @FindBy to use when I run the tests .
e.g - If I wish to run test on android device how do I let appium know to use @AndroidFindBy and vice verse.

Thanks in Advance!

Hi,

We don’t need to worry about this. All this is done automatically in the background. When you run your scripts for Android, the driver is instantiated as AndroidDriver -

WebDriver driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

After this, when it looks for the elements - it will automatically search for @AndroidFindBy(...). Similar is the case with iOS, where since the driver would be of type IOSDriver, the driver will always look for @IOSFindBy(...)

In short, just run your scripts for Android or iOS. The driver would automatically pick up from @AndroidFindby() or @IOSFindBy on its own.

1 Like

Thank you it helped!