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.
Alexey R.
11.6k5 gold badges21 silver badges39 bronze badges
asked Aug 8, 2018 at 5:50
7
  • you will need to provide us with your HTML code too. Please avoid using absolute Xpath Commented 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 Commented Aug 8, 2018 at 5:52
  • the xpath has 4 matching node so that [3] requires an extra ")". Commented Aug 8, 2018 at 5:55
  • driver.find_element_by_xpath('(.//*[@id="Toolbar"]/table/tbody/tr/td[2]/a[1]/span)[3])').click() Commented 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. Commented 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.

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.