如何查找包含& nbsp;的元素使用硒 [英] How to find an element which contains   using Selenium

查看:153
本文介绍了如何查找包含& nbsp;的元素使用硒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<td>By Company&nbsp;&nbsp;</td>

我需要捕获上述元素的xpath.我尝试了以下替代方法,但是在chrome中似乎没有任何效果.您能建议其他任何选择吗?

I need to capture xpath of the above element. I tried following alternatives, but nothing seems to be working in chrome. Can you please suggest any other option.

"//td[normalize-space(text())='By Company\u00a0']"
"//td[normalize-space(text())='By Company\u00a0\u00a0']"
"//td[text()='By Company\u00a0']"
"//td[text()[normalize-space(.)='By Company\u00a0']]"
"//td[text()[normalize-space()='By Company\u00a0']]"

推荐答案

要查找元素:

<td>By Company&nbsp;&nbsp;</td>

您可以使用以下任一 :

You can use either of the following xpath:

  • 使用text():

"//td[text()='By Company\u00A0\u00A0']"

  • 使用contains():

    "//td[contains(., 'By Company\u00A0\u00A0')]"
    

  • 但是,理想情况下,您最好避免使用 NO-BREAK SPACE 字符,并使用以下任一解决方案:

    However, ideally you may like to avoid the NO-BREAK SPACE character and use either of the following solutions:

    • 使用starts-with():

    "//td[starts-with(., 'By Company')]"
    

  • 使用contains():

    "//td[contains(., 'By Company')]"
    

  • 您可以在以下位置找到相关的详细讨论:

    You can find a relevant detailed discussion in:

    Unicode字符'NO-BREAK SPACE'(U + 00A0)

    这篇关于如何查找包含&amp; nbsp;的元素使用硒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆