0
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.

SyntaxError:

Failed to execute 'evaluate' on 'Document': The string 
'(.//*[@id="Toolbar"]/table/tbody/tr/td[2]/a[1]/span)[3])' 
is not a valid XPath expression.
7
  • you will need to provide us with your HTML code too. Please avoid using absolute Xpath
    – Yu Zhang
    Aug 8, 2018 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, 2018 at 5:52
  • the xpath has 4 matching node so that [3] requires an extra ")". Aug 8, 2018 at 5:55
  • driver.find_element_by_xpath('(.//*[@id="Toolbar"]/table/tbody/tr/td[2]/a[1]/span)[3])').click() Aug 8, 2018 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. Aug 8, 2018 at 6:20

1 Answer 1

2

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.

2
  • 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. Aug 9, 2018 at 5:00
  • How does adding an extra ')' help. You should be getting the 3rd span without that ')'. Aug 9, 2018 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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