【问题标题】:How to automatically pass an XPath generated by FirePath to a Javascript function如何自动将 FirePath 生成的 XPath 传递给 Javascript 函数
【发布时间】:2014-02-27 18:04:01
【问题描述】:

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

有可能吗?有人可以指导我如何做到这一点吗?

【问题讨论】:

标签: javascript jquery dom xpath firebug


【解决方案1】:

我看到了两种可能性:

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

【讨论】:

    【解决方案2】:

    我的解决方案是修改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);
    
                }
         },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-23
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 2017-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多