Xpath vs. iOS Predicate

Appium 1.6.4, Xcode 8.2, iOS 9.3.5
I want find element by xpath
How can I find this same element using iOS Predicate?

something like:

driver.findElement(MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeNavigationBar'")).
                findElement(MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeStaticText' AND visible == 1"))

Thanks it is helpful

Hey Aleksei,

I use arc for finding and interacting with mobile elements before using them in code.

In above case I would have used

@driver.find_element(:xpath, “//XCUIElementTypeButton[contains(@label,‘create a site’)”]

can you please clarify how to use MobileBy.iOSNsPredicateString in case of arc ?


@VikramVI examples are here

Thanks but this page doesn’t say how to use it with arc, have you tried using it with arc earlier ?


@VikramVI sorry. “arc” is ?

Appium Ruby Console https://github.com/appium/ruby_console

I use ARC for interrogating app and finding elements before using them in actual script.

Older version of Appium Desktop had feature where one can test element locator which is missing in newer version. Thus I find ARC useful to find whole page source and derive element locator out of it.

@Aleksei apologies for not giving enough info earlier.

Sorry no idea for ruby. I am with java.

@Aleksei got it working as

@driver.find_element(:predicate,“label==‘Create a site’”)

Can you clarify what technique do you use to explore native app and identify correct mobile elements’ identifer ?


@VikramVI normally i use getPageSource for iOS as it is the only source what Appium sees. Where name tag is ID. Aslo i put myself any ID values needed to me both in Android and iOS client. IDs eliminate most problems how to find elements.

1 Like

@Aleksei Thanks for quick info, this is unique approach and makes automation tester’s life much easier :slight_smile:

I assume you put accessibility id for iOS and android:id for Android right ?

@VikramVI yes. For iOS i put accessibility ids in two places: storyboard and sometimes of it not enough in code.

Also sometimes i do not see value of Text with iOS. I duplicate this into accesibility Value and see this in Value tag.

Thanks a ton for detailed info. I will try to enforce this practice in my project as well.

Best Regards,