如何自动将FirePath生成的XPath传递给Javascript函数
我正在做一些与XPath相关的工作,用户应该单击任何DOM元素,然后生成它的XPath。目前我正在使用FirePath(Firebug扩展),但我需要删除从那里复制粘贴XPath的过程(出于自动化目的),而是在单击后生成XPath时将其传递给JavaScript函数如何自动将FirePath生成的XPath传递给Javascript函数,javascript,jquery,dom,xpath,firebug,Javascript,Jquery,Dom,Xpath,Firebug,我正在做一些与XPath相关的工作,用户应该单击任何DOM元素,然后生成它的XPath。目前我正在使用FirePath(Firebug扩展),但我需要删除从那里复制粘贴XPath的过程(出于自动化目的),而是在单击后生成XPath时将其传递给JavaScript函数 有可能吗?有人能指导我如何实现这一目标吗?我认为有两种可能实现这一目标: 更改以允许导出生成的XPath 创建一个脚本,首先执行Firebug/FirePath中的路径,然后将其导出 我的解决方案是修改FirePath的stopIn
有可能吗?有人能指导我如何实现这一目标吗?我认为有两种可能实现这一目标:
我的解决方案是修改FirePath的
stopInspection()
函数。以下是相关代码:
stopInspecting: function(inspectingNode, cancelled) {
this.inspecting = false;
var latestXpath = getXPathFromNode(inspectingNode); // getting xpath
// in Firebug 1.7 the signature of this method changed
// before there was only on arg: cancelled.
if (!Firebug.Inspector._resolveInspectingPanelName) {
cancelled = inspectingNode;
}
if(cancelled) {
this.navigate(this.previousLocation);
this.fireSIMSBar.selector = this.previousSelector;
delete this.previousLocation;
delete this.previousSelector;
}
this.fireSIMSBar.reset();
this.fireSIMSBar.evaluate();
// Passing xpath to javascript function
var doc = Application.activeWindow.activeTab.document;
var win = doc.defaultView;
win.wrappedJSObject.myFunction(latestXpath);
}
},
据我所知,我想你已经可以解决你的问题了。所以,如果你发布一个你是如何解决它的答案,那就太好了。@SebastianZartner我已经添加了代码