首页 > 解决方案 > 带有法语特殊字符 (è d') 的无效 XPath

问题描述

如果 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),但不工作。

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

标签: xmlpython-2.7xpathselenium-chromedriverrobotframework

解决方案


è在 XPath 中使用字符并没有错。

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

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

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

推荐阅读