selenium.common.exceptions.InvalidSelectorException: Message: invalid selector

Unable to locate an element with the xpath expression .//*[@id="Toolbar"]/table/tbody/tr/td[2]/a[1]/span)[3] because of the following error.


Failed to execute 'evaluate' on 'Document': The string 
is not a valid XPath expression.
  • you will need to provide us with your HTML code too. Please avoid using absolute Xpath – Yu Zhang Aug 8 '18 at 5:51
  • 2
    (.//[@id="Toolbar"]/table/tbody/tr/td[2]/a[1]/span)[3]), you have an extra ")" right after span – Yu Zhang Aug 8 '18 at 5:52
  • the xpath has 4 matching node so that [3] requires an extra ")". – Ankit Kumar Aug 8 '18 at 5:55
  • driver.find_element_by_xpath('(.//*[@id="Toolbar"]/table/tbody/tr/td[2]/a[1]/span)[3])').click() – Ankit Kumar Aug 8 '18 at 5:55
  • Try with ((//[@id="Toolbar"]/table/tbody/tr/td[2]/a[1]/span)[3]), there seems to be a syntax error in your xpath. – Kshetra Mohan Prusty Aug 8 '18 at 6:20

The error shows that the given expression is not valid. You seem to have an extra ')' in the xpath selector at the end. So browser wouldn't have even performed the DOM selection.

  • Since the same xpath has 4 matching node i have used that extra ')' for using the 4th matching node.Is there any another way to do kindly help me with that. – Ankit Kumar Aug 9 '18 at 5:00
  • How does adding an extra ')' help. You should be getting the 3rd span without that ')'. – Dakshinamurthy Karra Aug 9 '18 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.