用xpath选择子textnode

时间:2018-01-04 22:40:41

标签: python selenium xpath

我正在尝试使用selenium中的xpath匹配文本Test number 3

<span>
    <br> Test number 1
    <br> Test number 2
    <br> Test number 3
</span>

我可以获得span元素,然后从列表中获取与/span//text()[3]

类似的最后一个textnode

但我可以通过xpath直接检查测试编号3是否存在,如下所示

'//span[contains(text()," Test number 3")]'

这不起作用,只有部分工作是'//span[contains(text()," Test")]'

但我可以与Test number 3

匹配

1 个答案:

答案 0 :(得分:3)

您需要应用&#34;包含&#34;检查. - string value of the span nodetext()只匹配span内的第一个text node

.//span[contains(normalize-space(.), "Test number 3")]