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. 回答1: $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