It can become cross-platform, however, when you remember that XPath also allows boolean operations! In practice, the same attributes are not in use within XML sources produced for iOS and Android, so using predicates is often not a cross-platform approach.
In addition, the query is not cross-platform). If an extra layout is added to the hierarchy, or anything is shuffled around, it is likely to break. ///// (this query relies too much on hierarchical structure.//* (this is the worst possible query.Let's first take a look at some examples of queries which fail to meet this description:
In essence, these are queries which are anchored by elements uniquely identified by unchanging criteria.
#Xpath for text android
Sometimes, however, there is no alternative! (This goes for both Appium and Selenium, by the way: everything I'm about to say is equally valid for both automation tools.) Sometimes, you've been able to determine that XPath is, in your particular case, not actually expensive or slow (how did you determine this? You tried it!), and so you might prefer XPath to some of the platform-specific locator strategies (iOS Predicate String, or Android UISelector) in order to help your test code be more cross-platform.Įither way, what's important is that you write good XPath queries. These are really good reasons to avoid XPath if at all possible. With Appium specifically, using the XPath locator strategy can be expensive and slow, because of the extra work required to convert an app's UI hierarchy to XML, and then to match up found XML nodes with actual UI elements.XPath queries can be strictly hierarchical in nature, with the result that any change in the structure of your app (even accidental, or OS-caused) means a failure to find an element (or worse, finding the wrong element).
There are two main reasons for not using XPath:
#Xpath for text pro
I've written a couple editions of Appium Pro on the topic of finding elements reliably, including why you should consider not using XPath at all as part of your element-finding strategy.