4

Is it possible to get/generate the XPath, for a text selected in the HTML page. Say,I have opened an html file using a browser,say safari/firefox, now i select some text (using mouse), i want to generate/get the xpath for that. is it possible to get it programatically? how?

1

1 Answer 1

3

Some years ago I wrote the following sample and tested it to work with Mozilla and with Opera. It stores the selection in a cookie and can restore the selection from that cookie. It generates and stores an XPath expression to the startContainer and endContainer of the selected range and the numbers of the offset.

Sign up to request clarification or add additional context in comments.

1 Comment

I can load the sample home.arcor.de/martin.honnen/javascript/storingSelection1.html fine and it continues to work for me with Mozilla browsers like Firefox, it also works in Microsoft Edge. It does not work in Internet Explorer as that browser does not support XPath selection on nodes in HTML documents.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.