Need Help Using Xpath in a JavaScript


I'm trying to get a xpath from to front browser. But can't get it to work. I've tried several websites and xpaths.

There's an error message in the notification center, but it's not really helping since I can't even read the error...

Here's the code:

Screenshot 2021-01-21 at 18.13.54

I got the JavaScript from this forum, so it should work. Don't know what I'm doing wrong...

I think you mean "using Xpath" rather than "getting Xpan", so I hope you don't mind that I have revised your topic title to better reflect the question you have asked.

Get xpath with Java Script

Need Help Using Xpath in a JavaScript

This will greatly help you attract more experienced users to help solve your problem, and will help future readers find your question, and the solution.

1 Like

Xpaths are hard to use and work with. I much prefer using the JavaScript querySelector.

Please provide the URL of the target page, along with a screenshot highlighting the text you want, along with the resultant text you want. Then we can offer you much better help.

Please read:
Tip: How Do I Get The Best Answer in the Shortest Time?

1 Like

It’s an interesting question which of two things to go all in on:

  • XML technologies, such as XPath. (Also XSLT and DOM treewalking.)
  • Webby stuff, such as CSS Selectors.

The answer is, of course, both... :slight_smile:

1 Like