如何自动将FirePath生成的XPath传递给Javascript函数

时间:2014-02-11 06:18:22

标签: javascript jquery dom xpath firebug

我正在做一些与XPath相关的工作,用户应该点击任何DOM元素,并且应该生成XPath。目前我正在使用FirePath(Firebug扩展),但是我需要从那里删除复制粘贴XPath的过程(出于自动化目的),而是在点击后生成XPath时将其传递给JavaScript函数。

有可能吗?有人可以指导我如何实现这个目标吗?

2 个答案:

答案 0 :(得分:1)

我看到了两种可能性:

  1. 更改source code of FirePath以允许导出生成的XPath。
  2. 创建一个Selenium IDE脚本,首先在Firebug / FirePath中执行路径,然后将其导出。

答案 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);

            }
     },