From FirebugWiki

Revision as of 00:01, 22 November 2013 by Sebastianz (Talk | contribs)
Jump to: navigation, search

This command returns an array of HTML or XML elements matching the given XPath expression. This means it is actually a shortcut for document.evaluate().

Currently this command is limited to node arrays. See issue 18 for supporting other results to be printed.



$x(xpath [, contextNode [, resultType]])



XPath expression used to match the elements to return. This follows the syntax of document.evaluate(). (required)


Element used as root node for the XPath expression. (optional; added in Firebug 1.11)


Object type returned by the function. (optional; added in Firebug 1.11)

Option document.evaluate() equivalent Description
"number" XPathResult.NUMBER_TYPE Numerical value
"string" XPathResult.STRING_TYPE String value
"bool" XPathResult.BOOLEAN_TYPE Boolean value
"node" XPathResult.FIRST_ORDERED_NODE_TYPE Single HTML element
"nodes" XPathResult.UNORDERED_NODE_ITERATOR_TYPE Array of HTML elements



This returns an array of all <h1>s of a page.


This returns an array of all checkboxes of a page.


This checks whether there are more than five <h1>s in the page and returns true or false. (requires Firebug 1.11 or higher)


This returns an array of all text nodes within every first <b> of all <p>s of a page.

$x(".//button", $$("form")[1])

This returns an array of all <buttons> within the second <form> of a page. (requires Firebug 1.11 or higher)

$x("//p", document, "node")

This returns the first <p> inside the page. (requires Firebug 1.11 or higher)

See also

Personal tools