How to use/findElements - ByIosUIAutomation

Hi bootstrap/All,

Can you please provide me an example on how do i make/find the hierarchy to using ByIosUIAutomation -

1.Locate elements
2.Scroll to text or up/down
3.Locate /Select the Child
4.Get the count of the children from a parent.

For eg. ".elements()[0] or driver.findElementByIosUIAutomation(“tableViews()[0].cells()[0]”);
How do i know i need to put this from the Appium Inspector?


Not sure if the Inspector can find elements by using the IOS Automation. But you can use it in your tests, of course. Like you also do it in Android (I saw you question).

What i meant was that how i read the elements
like you mentioned in your example here - UIAutomator usage?

how is it that you write “.cells()” for getting the textview from it ,if there are multiple textviews then how would you be referring to it in ?

In Android i am using UiSelector and UiScrollable for ByAndroidUiAutomator, can they be used for ByIosAutomation as well, i dont think so ?

Well, if you want to find the first TextView element from the first cell, you would use:
Or even better, if you want to find the specific textview element by something else than index, than you can use IOS Predicates.
Check this out:
They are a bit tricky and not that well documented, true.

MobileElement popularOptions = (MobileElement) driver.findElementByIosUIAutomation(“tableViews()[0].cells().firstWithPredicate(“name == New Delhi And NCR”)”);

I am trying to click on a button which opens the list and in that i want to click on the text by the name above.

IS this correct or do i need to -
MobileElement popularOptions = (MobileElement) driver.findElementByIosUIAutomation(“tableViews()[0].cells(1).textViews().firstWithPredicate(“name == New Delhi And NCR”)”);

Please explain with an example .

1 Like

Hi bootstrap,

Can you explain this with an example in java ,how to use predicates for the UiCatalog app or otherwise and how i can use (UIAElementArray) for scrollViews() or other functions in ByIosAutoamation.

That would be of great help!

Do you have some snippet of your app’s hierarchy on which you want to find a particular element? If so, put it here so we can discuss on a specific example

I am using the for reference in that there is a list

1.If i have to select on this element as shown in the pic , which could be anywhere dynamically ,how do i go about it by using ByIOSAutomation or with predicate,please tell with both examples.

I can easily use xpath or accessibility id ,but if it is dynamic and i have to scroll to find the element then how would i use predicates?

You can try something like this:

MobileElement cell=driver.findElementByIosUIAutomation(“tableViews()[0].cells().firstWithPredicate("staticTexts[0].label== ‘Page Control’'")”);

It means: “Give me the first cell which contains a UIAStaticText control with the name Page Control”

  1. Click on Locator in the Appium GUI
  2. Select strategy “ios-uiautomation”
  3. Test your locators

This locator should work if you paste it into the “value” section in the Appium GUI:

.tableViews()[0].cells().firstWithPredicate("name beginswith 'Page Control'")

Example locator for UICatalog as you would use it in code:

locator = '.tableViews()[0].cells().firstWithPredicate("name beginswith \'Page Control\'")' 
driver.find_element_by_ios_uiautomation(locator).click() # click on the element

Thanks @JessicaSachs for the example , worked perfectly!

1 Like

Hi @JessicaSachs ,

I have a query in the picture below

is this syntax correct - .scrollViews()[0].textfields().firstWithPredicate("value MATCHES ‘Email address’ ") to find the locator.

It doesnt seem to work .

Replace MATCHES with like or beginsWith

I don’t think MATCHES is valid. matches might be.

See Cocoa (iOS) predicate programming guide

i am not really able to use value and i have tried like,beginswith and matches too.

as described above i actually wanna find this element with the field value,can you provide the syntax for this?

I build my locators from the top down.

  1. Does .scrollViews()[0] return the element I want? Yes? Next.
  2. Does .scrollViews()[0].textfields() return >= 1 element? Yes? Next.
  3. Does .scrollViews()[0].textfields().firstWithPredicate("value beginsWith 'Email'") return the element I’m interested in? Yes? There we go. There’s our locator.

To determine the above questions, I suggest using the Inspector’s “Locators” tab to test. For more advanced usage of firstWithPredicate, see the programming guide I linked above.


FYI When using the ios-uiautomation locator strategy… I strongly advise against using indexes to find your element.

Why? Something like .buttons()[0] will almost always be true on any screen in your app. Something like .buttons().firstWithPredicate("value beginsWith 'Login'") is less prone to false positives.

However, scrollviews and tableviews don’t usually have any distinguishing attributes on them that you can hook onto.

1 Like

Actually i have understood this part and tried the same way as mentioned,however it doesnt just seem to work for me .

just expanding the element …to show you ,thanks for your promt reply though!

Thanks @JessicaSachs for the examples. That help a lot.
Could please tell me where to find the guide for IosUIAutomation.
I am still struggling find elements.

great post. this just helped me out quite a bit just now!