Finding elements by xpath in Appium using XCUITEST driver

浪子不回头ぞ 提交于 2020-01-01 18:38:16

问题


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


回答1:


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.




回答2:


With little workaround, you can use the old graphical appium to find xpath of view elements for using with Appium v1.6 Follow the step 1 in this link on medium: The good old Appium inspector, with a bit workaround




回答3:


The above answer by JaysonP works fine but there still is a way to use the appium inspector.

  1. Run appium you are using (appium 1.6.x ) from terminal/command line
  2. Open appium GUI application but Do NOT run it
  3. In the GUI, give the App Path
  4. Make sure both the GUI version and the one you are running on terminal are using the same port. Once again DO NOT launch appium from the GUI
  5. Click the Inspector button without launching appium
  6. Inspector window should be opened and you can use the way you have been using it previously


来源:https://stackoverflow.com/questions/39662409/finding-elements-by-xpath-in-appium-using-xcuitest-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!