我正在做一些与XPath相关的工作,用户应该单击任何DOM元素并生成它的XPath。目前我正在使用FirePath (Firebug扩展),但是我需要删除从那里复制粘贴XPath的过程(为了自动化目的),并在单击后生成XPath时将其传递给JavaScript函数。
有可能吗?有人能引导我朝着正确的方向去完成这个任务吗?
发布于 2014-02-27 09:50:49
我的解决方案是修改stopInspecting()函数的FirePath。以下是相关代码:
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);
}
},发布于 2014-02-27 08:38:32
我认为如何实现这一目标有两种可能性:
https://stackoverflow.com/questions/21694535
复制相似问题