For positioning page elements ,xpath Is the most powerful way , It's stable and versatile . But whether it can be used well is another matter , If not, it's a hole . Not much nonsense , Enter the topic :




As shown above , We need to position “_ Provincial company ” Fold button at front ,xpath How do you write it? ? Obviously , there id='_easyui_tree_1' Not a very safe fixed value ,tag
name It's even more outrageous . probably id='ltree' It's reliable , But I can't id No need id( In addition to the login page ), in fact id It's a good positioning tool , But it's not used in many scenarios , Then cultivate and use xpath Our habits and abilities are very important , Let's write down this example :

Step by step analysis :


1. use xpath, Because it's about “_ Provincial company ” Front fold , that “_ Provincial company ” I can't get away with it , with “_ Provincial company ” As a starting point ,xpath=.//span[text()="_ Provincial company "]

2. Axis required , Foldour is a former brother ,/preceding:siblind::span

3. There are 2 Brothers ? ha-ha , from “_ Provincial company ” Start counting up , We're looking for the top span, In the middle is the icon of the folder . Second brother :[2]

Combine :

xpath = .//span[text()="_ Provincial company "]/preceding-sibling::span[2]


Of course, it can also be directly located here “_ Provincial company ” Father of <div id="_easyui_tree_1" class="tree-node"
>, And then take the first one down span children :.//span[text()="_ Provincial company "]/parent::div/span[1]

Another group :




If you don't want to count , You can use it directly preceding-sibling 了 .

Come here for a while , New progress , Update at any time !