尝试从此 HTML 片段创建 XPath [英] Trying to create XPath from this HTML snippet
问题描述
我在编写 XPath 时已经玩了一段时间了,但无法准确地想出我想要的东西.
我正在尝试根据已知文本(下面代码片段中的 myidentity)为链接(下面代码片段中的 click1 和 click2)编写 XPath.有人可以查看并提出可能的解决方案吗?
HTML 代码片段:
<a onclick="mycontroller.goto('xx','yy'); return false;"href="#"><img src="images/controls/inheritance.gif"/></a>我的身份<跨度><a onclick="mycontroller.goto('xx','yy'); return false;"href="#">click1<a onclick="mycontroller.goto('xx','yy'); return false;"href="#">click2</span>
查看 Macro 的回答 - 应该使用这种形式.
//div[text()[contains(., "myidentity")]]/span/a[2]
以下仅适用于包含 div 中的一段文本.
您需要根据包含您的身份文本的文本进行选择.
点击 1 的 Xpath
//div[contains(text(),"myidentity")]/span/a[1]
click2 的 Xpath
//div[contains(text(),"myidentity")]/span/a[2]
I have played for a while writing XPath but am unable to come up with exactly what I want.
I'm trying to write XPath for link(click1 and click2 in code snippet below) based on known text(myidentity in code snippet below). Can someone take a look into and suggest possible solution?
HTML code snippet:
<div class="abc">
<a onclick="mycontroller.goto('xx','yy'); return false;" href="#">
<img src="images/controls/inheritance.gif"/>
</a>
myidentity
<span>
<a onclick="mycontroller.goto('xx','yy'); return false;" href="#">click1</a>
<a onclick="mycontroller.goto('xx','yy'); return false;" href="#">click2</a>
</span>
</div>
See Macro's answer - this form should be used.
//div[text()[contains(., "myidentity")]]/span/a[2]
The following only works with one section of text in the containing div.
You'll need to select based on the text containing your identity text.
Xpath for click1
//div[contains(text(),"myidentity")]/span/a[1]
Xpath for click2
//div[contains(text(),"myidentity")]/span/a[2]
这篇关于尝试从此 HTML 片段创建 XPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!