tell me how to locate the parent and sibling nodes when locating elements on the mobile app
Here are two of the most commonly used methods, Other ways to see other chapters of the blog
Instance:
We are now going to navigate to the second element under LinearLayout under relativelayout[0,1285][1080,1465]
One, Use the sibling node to locate the
Usage:
following-sibling:: Find the next node of the current node, that is, the brother node
Preceding-sibling:: Find a node in front of the current node, that is, the brother node
Here I use this sentence to find the element we need to locate:
xpaht=//android.widdget.textview[@text = "annual yield (History)"]/ FOLLOWING-SIBLING::ANDROID.WIDGET.RELATIVELAYOUT/ANDROID.WIDGET.LINEARLAYOUT[0]/ANDROID.WIDGET.LINEARLAYOUT[1]
Second, locate through parent node
How to:
Parent:: Or. Find the parent node of the current node
Here's a way to use the parent node to locate the element we need to find:
Xpath =//android.widget.textview[@text = "annual rate of Return (history)"]/parent::android.widget.linearlayout/ ANDROID.WIDGET.RELATIVELAYOUT/ANDROID.WIDGET.LINEARLAYOUT[0]/ANDROID.WIDGET.LINEARLAYOUT[1]
The last sentence can be used. Instead of Parent::
Appium position element relative----parent/sibling node positioning