Xpath Slowdowns my execution- iOS

I am using xpath to identify and click or play with elements for my iOS app.

Could someone quickly let me know how to use the iOSUIAutomation strategy?

Thanks,
Sathya

Hi Sathya,

to use uiautomation you can use MobileBy.IosUIAutomation. You also should take a look at the api documentation https://developer.apple.com/library/ios/documentation/DeveloperTools/Reference/UIAutomationRef/

Here is an example with Java code:
If you have an xpath like this:

By locator = MobileBy.xpath("//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell");

it will looks like this when it is transformed to uiautomation:

By locator = MobileBy.IosUIAutomation(".tableViews[0].cells()");

or if you just want all visible cells:

By locator = MobileBy.IosUIAutomation(".tableViews[0].visibleCells()");

As you see the uiautomation indexes are zero based, this can be an error source when you transform xpath to uiautomation.
Also if you read the api docs from the link above you will see that the uiautomation code I posted above looks incorrect and it should looks like this:
UIATarget.localTarget().frontMostApp().mainWindow().tableViews[0].cells()

But Appium provides some kind of shortcut and you can leave out UIATarget.localTarget().frontMostApp().mainWindow() for elements you query form the main window. If you want to query elements that are not in the main window you have to provide the complete uiautomation call e.g. in my app automation I use UIATarget.localTarget().frontMostApp().navigationBar().leftButton() to get the back button.

If you have more complex xpath with conditions you have to use predicates. Here the Appium documentation for it http://appium.io/slate/en/1.4/?python#ios-predicate.
Here an example from my code IosUIAutomation(".activityIndicators().withPredicate(“value = ‘1’”)");

I hope this helps.

Hi,

the xpath:

//UIAApplication[1]/UIAWindow[1]/UIAButton[5]

should it look like that ?

target.frontMostApp().mainWindow().buttons()[5]

It seems not to be correct, but that works:

target.frontMostApp().mainWindow().buttons()[4]

Why ? Why is it 4 instead of 5 ?