使用 XCUITEST 驱动程序在 Appium 中通过 xpath 查找元素 [英] Finding elements by xpath in Appium using XCUITEST driver

查看:32
本文介绍了使用 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.

我已经启动并运行了驱动程序,但是大多数元素都使用框架中的 xpath 定位(我知道这并不理想)大多数元素没有标签、名称或可访问性标签.因此,目前 90% 的元素都排除了 :name 定位器.

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.

xpaths 似乎迎合了旧的苹果框架 (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.

这篇关于使用 XCUITEST 驱动程序在 Appium 中通过 xpath 查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆