Selenium说span的无效xpath

时间:2016-04-25 01:22:35

标签: java xpath selenium-webdriver

HTML:

<div class="accept"><a class="red_keep popup_action"><span>Click here to view terms</span></a></div>

我试过的Xpath:

1. //span[text()='Click here to view terms']
2. normalize-space(//href[@class="red_keep popap_action"]/text()='Click here to view terms')

从xpath上面,它们都没有工作。

1 个答案:

答案 0 :(得分:1)

假设在对空格进行规范化后(使用span),您需要将normalized-space()与其文本内容进行匹配,那么XPath可以是以下之一:

//span[normalized-space(text())='Click here to view terms']
//span[text()[normalized-space(.)='Click here to view terms']]

第一个XPath仅在目标文本节点是span第一个子节点时有效,而第二个XPath应该无论如何都可以。