我应该使用哪种方法(最快)来选择元素? [英] Which method should I use (fastest) to select element?

查看:25
本文介绍了我应该使用哪种方法(最快)来选择元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,有很多不同的方法可以在驱动程序之间选择元素.我想知道哪个最快,最适合原生应用(iOS和Android).

Well there are a lot of different methods to select elements between Drivers. I would like to know which one is the fastest and the most suitable for native apps (iOS and Android) .

Appium Driver 类有:

With the Appium Driver class there is :

findElementByAccessibilityId(String using)

移动类有:

findElement(org.openqa.selenium.By by) //with ById/Xpath/Name/ClassName...

Android 和 iOS 驱动程序类有:

With Android and iOS driver class there are :

findElementByAndroidUIAutomator(String using)
findElementByIosUIAutomation(String using)

使用 RemoteWebDriver 类有:

And using the RemoteWebDriver class there are :

findElementById();
findElementByXPath();
findElementById(); //css, className etc... -> WebElement which can be cast in mobileElement

所以我猜使用 UIAutomatorUIAutomation 会更快,但是 Android 2.3+ 需要 selendroid.

So I'm guessing using UIAutomator and UIAutomation are faster but selendroid is needed for Android 2.3+.

你是怎么做的,为什么?你能给我提供一些 findElementByAndroidUIAutomator(String using)findElementByIosUIAutomation(String using)

How do you do and why? Can you provide me some examples for findElementByAndroidUIAutomator(String using) and findElementByIosUIAutomation(String using)

我发现 XPath 选择器存在一些问题.从我的角度来看,使用 findElement(By.name) 似乎很简单.

I saw there are some issues with XPath selectors. From my point of view using findElement(By.name) seems quite simple.

推荐答案

好吧,只要可以,就使用 UiAutomator、UiAutomation(默认情况下,客户端库会这样做 - 对于 Id/Name 等...-,除了 XPath,它速度较慢,请在没有选择的情况下使用它.

Well , just use UiAutomator, UiAutomation when you can (by default client-libs do it -for Id/Name etc...-, except for XPath which is slower, so use it when you haven't the choice.

https://github.com/appium/java-client/issues/158

我使用了一个函数,它接受字符串选择器的参数和每个类型的自定义枚举(id、xpath,甚至自定义类型,如 Android parentIdChildEditText-仍然使用 UiAutomator- 等...) -> 不要这样做!

经过多年的经验,如果可以,请使用 AccessibilityId:其中

After years of experience, just use AccessibilityId if you can : which

  • 对于 ios 是 name 在您的 appium xml 源中 名称您的 ios 开发人员的辅助功能标识符
  • 对于 android 是 contentDesc <=> 相同的 appium 源/开发标识符
  • for ios is name in your appium xml source <=> accessibilityIdentifier for your ios dev
  • for android is contentDesc <=> same appium source/dev identifier

否则,最简单的 选择器适合您(即使是带有文本的 xpath,但最好使用自定义测试 ID).对于这些类型的测试,选择器性能是最后一个问题,维护和健壮性是重点.

Otherwise, the simplest selector for you (even xpath with text, still better to have custom test-id though). For these type of tests, selector performance is your last problem, maintenance and robustness are the main points.

这篇关于我应该使用哪种方法(最快)来选择元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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