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

getting InvalidSelectorException while locating for an element using the using same xpath that works fine in firepath with 1 matching node

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.

错误说明了一切,您的 xPath 表达式无效。您不能将预定义的关键字更改为 Text(),例如 text()。尝试 //a[contains(text(),'Forgot Password')]//a[contains(.,'Forgot Password')]

关于 InvalidSelectorException 的更多信息请参考 this

您输入的语法或表达式搞砸了

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

这必须像

//a[contains(text(),'Forgot Password?')]