1

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??

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
user9686029
  • 252
  • 1
  • 2
  • 11

1 Answers1

6

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]"
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352