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.

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
Antarktis
  • 143
  • 10

1 Answers1

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()
DebanjanB
  • 118,661
  • 30
  • 168
  • 217