Finding similar element across Android and iOS with the same script


After searching these forums, i failed to find an answer so I guess I’ll ask it here.
I am writing test scripts in java using the Android/iOS driver. (maybe I should use AppiumDriver)?

I have a native application on iOS and Android. I would like to implement something along the lines of
Pseudo code

if AndroidTest
return driver.findElementsByName(“blahblah”)

Is there anyway I can solve this?
I was thinking about using the page factory annotations for @AndroidFindBy and so on, but im not 100% sure on those.

Thank you,

Jonathon Ramey.

You can implement cross-platform page objects.

@AndroidFindBy and @iOSFindBy is the correct way. You can combine them together:

@AndroidFindBy(“the relevant locator strategy for Android”) //this strategy will be used when Android is here
@iOSFindBy(“relevant locator strategy for iOS”) //this strategy will be used when iOS is here
MobileElement yourElement.

AndroidDriver and iOSDriver both extend AppiumDriver. So you can use parameterized tests:

//it is parameterized test
public class AppiumJUnitTest{

//this is set up by given parameters before test is started
private AppiumDriver driver;

public void test() throws Exception{
//code which works agains Android and iOS


It is possible to combine them with the Selenium @FindBy annotations if there is the similar browser UI.


1 Like

Awesome, thank you so much!

Awesome, this is exactly what I was thinking to use.
I don’t understand though if an elements has 1 strategy for iOS and one for Android, how does it know which one to look? how does it detect when we are on Android and when we are in iOS?

I have this issue where I use 2 widget classes in a PO class, one widget is defined only with @AndroidFindBy location strategy and one is defined only with iOSFindBy strategy. From the server logs (when running on iOS device) I see that the Android widgets are searched also by the name of the variable defined in the PO class, which is weird.

Thank you!!!

Which client version do you use? There had been bugs which were fixed at 3.0.0, 3.1.0, 3.2.0. Also can you provide client (Java) code samples and server output as gists?

It would be cool if you open an issue with attached gists here: It is difficult to me to react on discuss replies. If it is real bug it will be fixed and I’ll include you name to release notes and README :slightly_smiling:


I am using latest java client 3.3.0. The strange thing is that I just noticed it happens when I am in debug mode in my IDE (intelliJ) - does this sound logical in any way :slight_smile: ?

Opened issue