XPath queries in Google Chrome console
I can use XPath queries in Google Chrome console like this:
a = $x('my/path')
However, what if I want to find XPath relative to another object? For example:.
b = a.$x('my/path')
(doesn't work) also:
b = $x('my/path', a)
crash: NotSupportedError: Failed to execute 'evaluate' on 'Document': The context node provided is null.
Does anyone know how to evaluate relative XPaths in Google Chrome Developer Console?
source to share
Evaluation $x
returns ...
function $x(xpath, [startNode]) { [Command Line API] }
So the syntax $x('my/path', a)
.
What matters is what the $x
array returns, but startNode
it requires a DOM node, so you need to take the element of the first request. The following example 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 .
source to share