的XPath在HTML页面的链接使用链接
我不能在我的HTML页面来标识的链接标签如下图所示:的XPath在HTML页面的链接使用链接
<a href="/somthing/confirm_delete_somthing?&id=12">Delete this monitor</a>
什么是XPath标识由链接标签Delete this monitor
?
类似//a[@label="Delete this monitor"]
?
将@label
替换为text()
,其代表节点的文本值。
//a[text()="Delete this monitor"]
对于情况的文字是另一条线路上,如
<a>
Delete this monitor
</a>
可以使用normalize-space()
功能,消除启动和尾随空格:
//a[normalize-space(text())="Delete this monitor"]
,非常感谢 – 2010-06-21 15:27:42
使用:
//a[. = "Delete this monitor"]
或
//a[normalize-space() ="Delete this monitor"]
这将选择节点,即使它是类似如下:
<a href="/somthing/confirm_delete_somthing?&id=12">Delete <strong>this</strong> monitor</a>
相反,从目前接受的答案确实表达不是选择这样一个节点。
让我说我不知道节点的结束,即我知道它将开始与“删除这个”,但不知道第三个词是什么,然后我用什么?还是'normalize-space()'会起作用? – 2010-06-25 15:16:56
@Mo:使用:'starts-with(normalize-space(),'删除这个')' – 2010-06-25 15:55:05
好问题(+1)。看到我的答案比目前接受的更好的解决方案。 :) – 2010-06-21 16:12:35