相关疑难解决方法(0)

xpath中// node和/ descendant :: node之间有什么区别?

我在使用Selenium在网页中定位元素时使用了大量的XPath,并且最近已经从使用node1 // node2转向使用node1/descendant :: node2.这两种方法有什么区别?一个比另一个更有效吗?

用于演示的示例XML代码段:

<div id="books">
  <table>
    <tr><td class="title">Lord of the Rings</td><td class="author">JRR Tolkein</td></tr>
    <tr><td class="title">The Hitch-Hikers Guide to the Galaxy</td><td class="author">Douglas Adams</td></tr>
  </table>
</div>
Run Code Online (Sandbox Code Playgroud)

所以它是:

id('books')//td[@class='title']

要么:

id('books')/descendant::td[@class='title']

xpath

32
推荐指数
3
解决办法
5万
查看次数

标签 统计

xpath ×1