Skip to main content
 首页 » 编程设计

selenium之在使用相同的 xpath 定位元素时获取 InvalidSelectorException,该 xpath 在具有 1 个匹配节点的 firepath 中运行良好

2025年05月04日133mengfanrong


org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //a[Contains(Text(),'Forgot Password?')] because of the following error:  
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//a[Contains(Text(),'Forgot Password?')]' is not a valid XPath expression. 

请您参考如下方法:

您弄乱了输入的语法或表达式

//a[Contains(Text(),'Forgot Password?')] 

这必须像
//a[contains(text(),'Forgot Password?')]