I can use XPath queries in Google Chrome's console like that:
a = $x('my/path')
However, what if I want to find an XPath relatively to another object? E.g.:
b = a.$x('my/path')
(does not work), also:
b = $x('my/path', a)
fails with: NotSupportedError: Failed to execute 'evaluate' on 'Document': The context node provided is null.
Does anybody know how to evaluate relative XPaths in Google Chrome's developer console?
XPath (XML Path Language) is a query language that can be used to query data from XML documents. In RUEI, XPath queries can be used for content scanning of XML documents. A complete specification of XPath is available at http://www.w3.org/TR/xpath .
Evaluating $x
returns ...
function $x(xpath, [startNode]) { [Command Line API] }
So, the syntax is $x('my/path', a)
.
Important is that, $x
returns an array but startNode
requires a DOM node, so you have to take an element of the first query. The following sample demonstrates the behavior on the current page.
a = $x("//*[@id='question-header']")
> [ <div id="question-header">…</div> ]
b = $x(".//*[@href]/text()", a[0])
> [ "XPath queries in Google Chrome console" ]
Update: Here is the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With