我在使用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 ×1