我正在尝试匹配文本 Test number 3
在 selenium 中使用 xpath。
<span>
<br> Test number 1
<br> Test number 2
<br> Test number 3
</span>
我可以获取 span 元素,然后从列表中获取最后一个文本节点,类似于 /span//text()[3]
但是我可以直接通过 xpath 检查测试号 3 是否存在,如下所示
'//span[contains(text()," Test number 3")]'
这不起作用,只有部分工作是 '//span[contains(text()," Test")]'
但是我可以匹配 Test number 3
最佳答案
您需要对 应用“包含”检查。
- a string value of the span
node , text()
只会匹配第一个 text node在 span
内:
.//span[contains(normalize-space(.), "Test number 3")]
关于python - 使用 xpath 选择子文本节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48104633/