@FindBy is taking long time to detect native elements on the fly

Hi,
I am using appium 1.4.3 and java-client 3.4 to run appium scripts on ipad. It is a hybrid app I am Working on. When it is in web @FindBy is working fine but when in Native, @FindBy is taking long time to detect Native Elements. Is there any workaround.

The way i am finding Xpaths is :

//UIAButton[@name=‘SomeName’]

Adding up long time to execute a single scenario. Any help is Appreciated. Thanks.

don’t use xPath. it is slow in many cases. move to IDs.

isnt apple removing accessible-id tho, which field should we use? @FindBy (id = “”) isnt that using the accessible Id?

Appium supports PageFactory with annotations for native elemnts @AndroidFindBy and @iOSFindBy

im trying to get rid of xpaths also, but i wanna future proof it too, so i was using names, but that got depreciated, i have access to the source code, under the Accessibility view, i have Label, Hint, Identifier, now im assuming the Identifier relates to the id in appium. i put under that field ‘button_id’ and here is my code to click it, just assume everything else caps and driver are set up correctly bc it is. other ways work like the xpath.

@iOSFindBy(id = "button_id")
public IOSElement buttonClick

buttonClick.click()

but it doesnt work…

@Aleksei @Kyle
True, I see the loss in using xpaths but
When I try to get page source by driver.getpagesource It is giving me an xml that has only name and value pairs and I don’t see any id’s.
Is there any way to pull page source that yields id’s

1 Like

@SrinivasanSekar any suggestions

thanks for mentioning driver.getpagesource never knew about that. helpful feature.

normally i am putting IDs into iOS/Android client myself. if you are free to use your iOS/Android code = suggest the same. Not = ask dev help.

BTW: in many cases for iOS you need also to set accessibility value e.g. for cells where is known issue that text value is not visible for automation.

Yes , you can use ((IOSDriver)driver).getPageSource().

yup iv been using it already for debugging purposes.

can anyone post how they are using iOS/FindBy(id = “”) in their code? and where did you set the id in the source code.

@Boney Using pagesource is a hard way of finding something. You can use appium inspector or this one https://github.com/mykola-mokhnach/Appium-iOS-Inspector or Facebook webdriver agent https://github.com/facebook/WebDriverAgent/wiki/Starting-WebDriverAgent to identify the elements in your app.

Thanks for the Suggestion @SrinivasanSekar. Even Using appium inspector giving the same name and most of the elements that appium is interacting is like //UIAButton[@name=‘XYZ’] or //UIAStaticText[@name=‘XYZ’] or //UIATextField[@name=‘XYZ’] that is causing lot of time in finding them. Since the app i am working is IPAD only so i am trying to pull page source which i feel is the only way to inspect/identify any element.

Please Suggest if you find i am missing any here.

xpath will be time consuming to find generally so we suggest to use accessibility id for better results

Finally i found the answer - we need to use accessibility id instead of xpath when interacting with native elements, it is as fast as id (in web)