XPath 中的 .//和//* 有什么区别? [英] What is the difference between .// and //* in XPath?
问题描述
通过 Firebug 找到相对 XPath 时:它创建像
While finding the relative XPath via Firebug : it creates like
.//*[@id='Passwd']
---------如果我们不在开头使用点会怎样?
.//*[@id='Passwd']
--------- what if we dont use dot at the start what it signifies?
只需在 Xpath 中添加 //*
--它突出显示 --- 各种页面元素 ---------- 它意味着什么?
Just add //*
in the Xpath --
it highlights --- various page elements ---------- what does it signify?
以下是 Gmail 密码字段的 XPath.*
的意义是什么?
Below are XPaths for Gmail password fields. What is significance of *
?
.//*[@id='Passwd']
//child::input[@type='password']
推荐答案
这些表达式都选择了不同的节点集:
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.
这篇关于XPath 中的 .//和//* 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!