问题
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) .
With the Appium Driver class there is :
findElementByAccessibilityId(String using)
With the Mobile class there is :
findElement(org.openqa.selenium.By by) //with ById/Xpath/Name/ClassName...
With Android and iOS driver class there are :
findElementByAndroidUIAutomator(String using)
findElementByIosUIAutomation(String using)
And using the RemoteWebDriver class there are :
findElementById();
findElementByXPath();
findElementById(); //css, className etc... -> WebElement which can be cast in mobileElement
So I'm guessing using UIAutomator and UIAutomation are faster but selendroid is needed for Android 2.3+.
How do you do and why? Can you provide me some examples for findElementByAndroidUIAutomator(String using) and findElementByIosUIAutomation(String using)
I saw there are some issues with XPath selectors. From my point of view using findElement(By.name) seems quite simple.
回答1:
You should follow this sequentially:
ID, Name, ClassName, XPath. Whatever is available first use it. You can also ask your developers to add unique id for each element which is consider to be the best way.
回答2:
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.
I use a function which takes in parameter the string selector and a custom enum for each type (id, xpath, even custom type like for Android parentIdChildEditText-still using UiAutomator-, etc...)
See https://github.com/appium/java-client/issues/158
来源:https://stackoverflow.com/questions/28547434/which-method-should-i-use-fastest-to-select-element