使用XCUITEST驱动程序在Appium中通过xpath查找元素
更新自动化框架的任务落在了我身上.我是iOS测试的新手,因此无法使用Appium-1.6.0-beta1中的新XCUITEST驱动程序.
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.
我已经启动并运行了驱动程序,但是大多数元素是使用xpaths定位在框架中的(我完全不理想),大多数元素没有标签,名称或可访问性标签.因此::name定位符目前被排除在90%的元素之外.
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.
xpath似乎适合于旧的Apple框架(UIAutomation),如下所示:
The xpaths seem to be catering to the old apple framework (UIAutomation) and look like the following:
//UIAApplication[1]/UIAWindow[4]/UIAAlert[1]
我尝试过这样的事情:
//XCUIApplication[1]/XCUIElementTypeWindow[4]/XCUIElementTypeAlert[1]
这些没有运气就被传递到了driver.find_element(:xpath, xpath_value)
中.我似乎找不到任何相关的文档,并且在appium讨论论坛上收效甚微.
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!
谢谢, 彼得
并非所有XCUI元素都是从UIAutomator直接传输的.我一直在使用的方法是在没有所需的xpath的情况下运行测试,并且在打开屏幕时想要去:
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());
然后,只需阅读XML即可获得所需的项目.繁琐得多,但是在1.6BetaX中没有appium检查器,这是我知道如何获取XCUI层次结构的唯一方法.
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.