简体   繁体   English

Selenium xPath文本连接

[英]Selenium xPath text concatenation

I'm trying to find an element by it's text. 我试图通过它的文本找到一个元素。 However I'm facing a problem with concatenating two part of the "inner" text inside an element: 但是我遇到了在元素中连接“内部”文本的两部分的问题:

<p>
"Copied" 
"!" 
</p>

If I'm trying: 如果我正在尝试:

  1. "//p[contains(text(),'Copied!')]" nothing is being found "//p[contains(text(),'Copied!')]"没有找到任何东西
  2. "//p[contains(text(),'Copied')]; - works correctly "//p[contains(text(),'Copied')]; - 工作正常
  3. "//p[contains(text(),'!')]; - works correctly "//p[contains(text(),'!')]; - 工作正常

How it can be found? 如何找到它?

There is a new line between the text parts, you can use normalize-space() for this. 文本部分之间有一个新行,您可以使用normalize-space() From w3cschool 来自w3cschool

The normalize-space function strips leading and trailing white-space from a string, replaces sequences of whitespace characters by a single space, and returns the resulting string. normalize-space函数从字符串中去除前导和尾随空格,用单个空格替换空白字符序列,并返回结果字符串。

//p[normalize-space('Copied!')]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM