【问题标题】:Escaping Special Characters on cssSelector webdriver在 cssSelector webdriver 上转义特殊字符
【发布时间】:2013-10-22 00:29:45
【问题描述】:

如何转义以下特殊字符,以便使用 div 上的 ID 获取表单?这是我的 cssSelector:

#form > div:nth-child(4)>div:nth-child(2) > div:nth-of-type(2) > div:nth-of-type(2)

这是html代码:

div id="form:panelGridTransactionInfo" class="ui-panel ui-widget ui-widget-content ui-corner-all"

谢谢

【问题讨论】:

    标签: java selenium css-selectors selenium-webdriver


    【解决方案1】:

    你可以用这样的反斜杠转义它:

    #form\:panelGridTransactionInfo > div:nth-child(4) > div:nth-child(2) > div:nth-of-type(2) > div:nth-of-type(2)
    

    在 Java 中,重复反斜杠以在字符串中转义:

    "#form\\:panelGridTransactionInfo > div:nth-child(4) > div:nth-child(2) > div:nth-of-type(2) > div:nth-of-type(2)"
    

    【讨论】:

    • 您能否指出一些文档,为什么需要转义 : 字符以及在其他一些用例中,例如- 会自动转义吗?
    • @DebanjanB:没有自动转义的情况,除非您指的是 : 出现在字符串中,它没有任何特殊含义,只是一个字符。当它被误解为伪类分隔符时,您可以将其转义,就像这里的所有 :nth-child() 一样。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-01
    • 2019-01-29
    • 2018-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多