简体   繁体   English

找到包含空格的特定字符串的文本?

[英]Locating text that contains a certain string with space?

I am having a problem locate text containing at least two words. 我在查找包含至少两个单词的文本时遇到问题。

I need the next one: 我需要下一个:

<a e="k44.3" href="http://www.example.com">hello world</a>

and my XPath expression is: 我的XPath表达式是:

driv.findElement(By.xpath("//*[contains(text(),'hello world')]")).click();

But XPath took only the first word (output) from console: 但是XPath仅从控制台获取了第一个单词(输出):

  <a e="k77.4" href="http://www.example.com">hello</a>

How can I select the the one with the 'hello world'? 如何选择具有“ hello world”的那个?

尝试以下操作,让我知道它是否无效:

driv.findElement(By.xpath("//a[text()='hello world']")).click();

Try using this. 尝试使用这个。

Driver.findElement(By.linkText("hello world")); 

This will click on the links containing spaces also. 这也将单击包含空格的链接。

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

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