Search code examples
seleniumselenium-webdriverxpathwebdriverinvalidselectorexception

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


enter image description here

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.

enter image description here


Solution

  • Error says it all, your xPath expression is not valid. You cannot change pre-defined keyword, like text() to Text(). Try //a[contains(text(),'Forgot Password')] or //a[contains(.,'Forgot Password')]

    For more about InvalidSelectorException please refer this.