且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

XPath 中的 .//和//* 有什么区别?

更新时间:2022-06-22 05:40:01

这些表达式都选择了不同的节点集:

These expressions all select different nodesets:

.//*[@id='Passwd']

.//*[@id='Passwd']

'.'开头的意思是,当前的处理从当前节点开始.'*' 选择从当前节点降序的所有元素节点,其中 @id-attribute-value 等于 'Passwd'.

The '.' at the beginning means, that the current processing starts at the current node. The '*' selects all element nodes descending from this current node with the @id-attribute-value equal to 'Passwd'.

如果我们不在开头使用点会怎样?

What if we don't use dot at the start what it signifies?

然后,您将选择 整个 文档中 @id-attribute-value 等于Passwd"的所有元素节点.

Then you'd select all element nodes with an @id-attribute-value equal to 'Passwd' in the whole document.

只需在 XPath 中添加//* -- 它突出显示 --- 各种页面元素

Just add //* in the XPath -- it highlights --- various page elements

这将选择整个文档中的所有元素节点.

This would select all element nodes in the whole document.

下面提到:XPatht 的 Gmail 密码字段是真的 * 的意义是什么?

Below mentioned : XPatht's for Gmail Password field are true what is significance of * ?

.//*[@id='Passwd']

这将选择从 @id-attribute-value 等于 'Passwd' 的当前节点降序的所有元素节点.

This would select all element nodes descending from the current node which @id-attribute-value is equal to 'Passwd'.

//child::input[@type='password']

//child::input[@type='password']

这将选择所有名为 input@type-attribute-values 等于 'password' 的子元素节点.child:: 轴前缀可以省略,因为它是默认行为.

This would select all child-element nodes named input which @type-attribute-values are equal to 'password'. The child:: axis prefix may be omitted, because it is the default behaviour.

在 w3school.com 上解释了选择适当表达式的语法.

The syntax of choosing the appropriate expression is explained here at w3school.com.

轴(处理中的当前点)在在另一个 w3school.com 页面上进行了解释一>.

And the Axes(current point in processing) are explained here at another w3school.com page.