How to use xpath in chrome headless+puppeteer evaluate()?
How can I use $x() to use xpath expression inside a page.evaluate() ? As far as page is not in the same context, I tried $x() directly (like I would do in chrome dev tools), but no cigar. The script goes in timeout. $x() is not a standard JavaScript method to select element by XPath. $x() it's only a helper in chrome devtools . They claim this in the documentation: Note: This API is only available from within the console itself. You cannot access the Command Line API from scripts on the page. And page.evaluate() is treated here as a "scripts on the page". You have two options: Use document