Hey,
so i read xpath is bad in the long run and others saying its because most people dont know how to use it correctly. I was wondering if someone can explain to me using the more advanced techniques of Xpath. Something along the lines of
‘//*[@name= nameMe]’
Since appium 1.5 took out Find By.name i was hoping to replace it with xpaths that dont break as easily…
i have a screen shot below if someone could maybe write me an xpath for it using the name or value or label and maybe explain it a little bit would be so great and helpful. Thanks!
Your simplistic xpath you scoped is perfectly fine as long as it is ONLY finding the target element(s) you are profiling. The risk of using ‘//*[@name= nameMe]’ is that it will simply return the first element with that name attribute. If your page will only ever have just one element with that name, then it works.
However, if it has more than one element with that name then you’re in trouble as it will simply return the first matching element in the DOM. So I usually add the element type, in your case ‘//UIAButton[@name= nameMe]’ Now it will return the first Button with that name attribute, but not a UIATableView, UIATableGroup, UIATextField, etc.
Another reason I hear about not using XPath is that it’s slow/slower than by ID/name, and CSS, at least in the web world. I wonder if there is any translation of that to native apps side, or whether that’s actually irrelevant here in terms of native apps (e.g. find by ID, name, vs XPath, etc.).
XPath is considered one of the slower methods for finding elements. It’s not too bad on Android tests, but it can be devastatingly slow on iOS (I have not had a chance to touch the new iOS automation framework and library, yet though. The story might be different there!).