سؤال

I am doing some XPath related work where a user should click any DOM element and it's XPath should get generated. Currently I am using FirePath (Firebug extension), but I need to remove the process of copy-pasting the XPath from there (for automation purposes) and instead pass it to a JavaScript function when the XPath is generated after the click.

Is it possible at all? Can someone guide me in the right direction on how to accomplish this?

هل كانت مفيدة؟

المحلول 2

My solution was to modify the stopInspecting() function of FirePath. Here's the related code:

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

            }
     },

نصائح أخرى

I see two possibilities how to achieve that:

  1. Change the source code of FirePath to allow exporting the generated XPath.
  2. Create a Selenium IDE script that first executes the path in Firebug/FirePath and then exports it.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top