问题
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.
- Run appium you are using (appium 1.6.x ) from terminal/command line
- Open appium GUI application but Do NOT run it
- In the GUI, give the App Path
- 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
- Click the Inspector button without launching appium
- 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