为选定的文本节点生成/获取Xpath [英] generate/get the Xpath for a selected textnode

查看:84
本文介绍了为选定的文本节点生成/获取Xpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为HTML页面中选定的文本获取/生成XPath。说,我用浏览器打开了一个html文件,说safari / firefox,现在我选择了一些文本(使用鼠标),我想为它生成/获取xpath。是否有可能以编程方式获得它?怎么样?

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?

推荐答案

几年前,我写了下面的示例并测试它与Mozilla和Opera一起使用。它将选择存储在一个cookie中,并可以从该cookie恢复选择。它生成并存储一个XPath表达式给选定范围的startContainer和endContainer以及偏移量的数字。

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.

这篇关于为选定的文本节点生成/获取Xpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆