How to solve the error “Not a valid XPath expression”

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]"
    

Leave a Comment