I can not comment yet, so I will post it as an answer, but it is basically a clarification for Dmitry's answer.
.//View[@content-desc='PASSWORD']/../EditText
From tree view we can notice that the element we want to access has no unique identifier, but the View
which is on the same level of hierarchy has content-desc set to PASSWORD
. So, first we can look up for this element that can be somewhat uniquely identified by its description
.//View[@content-desc='PASSWORD']
The EditText we want to find is a child of the same parent, so we simple has to go one level up ..
and then get the element by its tag EditText
. In this way searching for element by tag EditText
will be limited to children of (2) View
.
This approach should be better then //EditText[2]
as it does not relay on order of elements in UI.
But Butch's answer is even more preferably, as it is always a better idea to supply unique identifiers for elements that are important for testing, as it will make test easier to maintain (no need to change locators on minor UI changes).