0

In selenium when I search for an id or an id in an xpath, I am instantly met with a syntax error. For example, if I run

driver.find_element_by_xpath("//*[@id="select-dance"]/option[2]").click() 

I immediately get an error

 driver.find_element_by_xpath("//*[@id="select-dance"]/option[2]").click() ^ SyntaxError: invalid syntax 

I tried saving "select-dance" to a variable and then putting that variable in, but that does not help either.

1
  • 2
    Use different quote: '//*[@id="select-dance"]/option[2]'
    – heemayl
    CommentedOct 12, 2018 at 20:41

1 Answer 1

2

This error message...

SyntaxError: invalid syntax 

...implies that the Locator Strategy which you have adapted have a Syntax error.

You have to either provide the entire XPath within double quotes (i.e. "...") and the attribute values within single quotes (i.e. '...') as follows:

driver.find_element_by_xpath("//*[@id='select-dance']/option[2]").click() 

Or you have to provide the entire XPath within single quotes (i.e. '...') and the attribute values within double quotes (i.e. "...") as follows:

driver.find_element_by_xpath('//*[@id="select-dance"]/option[2]').click() 
0

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.