user9686029
user9686029

Reputation: 262

How to solve the error "Not a valid XPath expression"

In selenium on Java, im try to find an element and select it on a webpage but it keep getting the error:

The string '//*[@id='app']/article/div[2]/section/div[1]/div[5]/div/section[2]/div[2]/div[1]/' is not a valid XPath expression. 

How can I get it at all??

Upvotes: 2

Views: 27907

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193338

The reason you are seeing an error as not a valid XPath expression because you have exactly 2 issues in it as follows:

  • As you are passing the xpath within single quotes i.e. '' you can't use the same for the attribute values.
  • Ideally an xpath shouldn't end with a /
  • So your effective xpath will be either of the following:

    '//*[@id="app"]/article/div[2]/section/div[1]/div[5]/div/section[2]/div[2]/div[1]'
    

    or

    "//*[@id='app']/article/div[2]/section/div[1]/div[5]/div/section[2]/div[2]/div[1]"
    

Upvotes: 6

Related Questions