【问题标题】:Invalid XPath with French special characters (è d')带有法语特殊字符 (è d') 的无效 XPath
【发布时间】:2020-10-01 19:26:55
【问题描述】:

如果 XPath 包含法语特殊字符(è d'),似乎 XPath 不起作用,出现以下错误

InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression 
//*[@class='v-menubar-menuitem']/*[contains(text(), 'Afficher la bibliothèque d'autorisations')] 
because of the following error:

SyntaxError: Failed to execute 'evaluate' on 'Document': 
The string '//*[@class='v-menubar-menuitem']/*[contains(text(), 'Afficher la bibliothèque d'autorisations')]' is not a valid XPath expression.

运行 windows 机器,也为 File 更改了 EOL(UTF-8,基于 unix),但不工作。

当我们以英文本地化运行时,这很好用

【问题讨论】:

    标签: xml python-2.7 xpath selenium-chromedriver robotframework


    【解决方案1】:

    在 XPath 中使用 è 字符没有任何问题。

    另一方面,d' 不是单个字符,而是 d 后跟单引号 ',并且单引号会干扰在您的字符串中用作字符串分隔符的单引号XPath。

    如果您将字符串分隔符更改为使用双引号,则内部单引号不会有问题:

    //*[@class='v-menubar-menuitem']
     /*[contains(text(), "Afficher la bibliothèque d'autorisations")]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-13
      • 2012-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-17
      相关资源
      最近更新 更多