Short answer
No. DOM.querySelector (and DOM.querySelectorAll) can only match element nodes, because the selector it takes is a CSS selector, and CSS selectors never target text nodes.
Why it works that way
The DevTools Protocol simply forwards the request to the browser’s native Element.querySelector() implementation. Per the WHATWG DOM spec, that function:
• accepts a CSS selector string;
• returns the first Element that matches;
• never returns comment, text, or processing-instruction nodes.
So if you try something like
{
"method": "DOM.querySelector",
"params": {
"nodeId": 1,
"selector": "#someDiv > #text"
}
}
you’ll just get
{ "nodeId": 0 }
(0 means “no node matched”).
Work-arounds
-
Walk the subtree yourself
• Call DOM.requestChildNodes (or DOM.getOuterHTML) on the element that contains the text.
• Inspect every returned child where node.nodeType === 3 (text nodes).
-
Use JavaScript/XPath through the Runtime domain
{
"method": "Runtime.evaluate",
"params": {
"expression": "document.evaluate('//text()[contains(., \"Some text\")]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)"
}
}
or
{
"method": "Runtime.callFunctionOn",
"params": {
"objectId": <id-of-the-parent-element>,
"functionDeclaration": "function() { return Array.from(this.childNodes).filter(n => n.nodeType === 3); }",
"returnByValue": false
}
}
-
Use DOM.performSearch (DevTools’ global search)
DOM.performSearch accepts the same query language as the Elements panel search (<text> to find text). It can return node IDs that contain a given string, though the results are still element nodes—you’d still have to examine their text children.
Takeaway
DOM.querySelector mirrors the browser’s CSS selector engine, so it is element-only. If you need text nodes, you’ll have to inspect children or switch to XPath/JavaScript via Runtime.* commands.