Search code examples
xpathappiumxctestappium-ios

Finding elements by xpath in Appium using XCUITEST driver


The task of updating an automation framework has fallen upon me. I'm new to iOS testing so I'm having trouble with the new XCUITEST driver in Appium-1.6.0-beta1.

I have the driver up and running, but the majority of elements are located using xpaths in the framework (not at all ideal I know) the majority of elements do not have labels, names, or accessibility tags. Thus :name locators are ruled out for 90% of elements at the moment.

The xpaths seem to be catering to the old apple framework (UIAutomation) and look like the following:

//UIAApplication[1]/UIAWindow[4]/UIAAlert[1]

I have tried soemthing like this:

//XCUIApplication[1]/XCUIElementTypeWindow[4]/XCUIElementTypeAlert[1]

These are passed into driver.find_element(:xpath, xpath_value) With no luck. I can't seem to find any documentation on this, and have had minimal success on the appium discussion forum.

Can anyone point me to a working example, or documentation? Any better way to do this?

Any input would really help!

Thanks, Peter


Solution

  • Not all of the XCUI elements are direct transfers from UIAutomator. The way I have been using is to run the tests without the xpaths you need and when you open onto the screen you desire go:

    System.out.println(driver.getPageSource());

    Then it is a matter of reading that XML to get the desired item. A lot more tedious but without the appium inspector in 1.6BetaX it's the only way I know how to get the XCUI hierarchy.