学习总结,有错误欢迎指出。
总结:通过Xpath路径表达式可以用来查找节点,表达式包含 路径 和 步(step)。
1. xpath路径表达式
- 路径
绝对路径:/step/step...
相对路径://step//step...
- 步(step)
结构:轴名称::节点测试[谓语]
说明:三段结构,分别使用::和[]间隔。当轴名称省略时,::间隔符也需要省略。
示例://child::input[@name="username"]
- 步(step)简化
1) /child::input[@name="username"] 等价于 /input[@name="username"]
说明:child使用频繁,可以省略(::间隔符也需要省略)。
2) /parent::* 等价于 /..
说明:当step中只有一个轴名称parent,且节点不限时,可以用 .. 代替。
2. 附录
常用轴名称:child、parent、preceding、preceding-sibling、following、ancestor