我正在做一些与XPath相关的工作,用户应该点击任何DOM元素,并且应该生成XPath。目前我正在使用FirePath(Firebug扩展),但是我需要从那里删除复制粘贴XPath的过程(出于自动化目的),而是在点击后生成XPath时将其传递给JavaScript函数。
有可能吗?有人可以指导我如何实现这个目标吗?
答案 0 :(得分:1)
我看到了两种可能性:
答案 1 :(得分:0)
我的解决方案是修改FirePath的stopInspecting()
功能。这是相关的代码:
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);
}
},