Puppeteer

How to use xpath in chrome headless+puppeteer evaluate()?

时光毁灭记忆、已成空白 提交于 2019-11-27 02:56:13
问题 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

Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout

ぐ巨炮叔叔 提交于 2019-11-26 22:20:32
问题 I'm using puppeteer and jest to run some front end tests. My tests look as follows: describe("Profile Tab Exists and Clickable: /settings/user", () => { test(`Assert that you can click the profile tab`, async () => { await page.waitForSelector(PROFILE.TAB); await page.click(PROFILE.TAB); }, 30000); }); Sometimes, when I run the tests, everything works as expectedly. Other times, I get an error: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout. at

How to run Puppeteer code in any web browser?

风流意气都作罢 提交于 2019-11-26 22:10:38
问题 I'm trying to do some web scraping with Puppeteer and I need to retrieve the value into a Website I'm building. I have tried to load the Puppeteer file in the html file as if it was a JavaScript file but I keep getting an error. However, if I run it in a cmd window it works well. Scraper.js: getPrice(); function getPrice() { const puppeteer = require('puppeteer'); void (async () => { try { const browser = await puppeteer.launch() const page = await browser.newPage() await page.goto('http:/

Puppeteer: Click on element with text

喜欢而已 提交于 2019-11-26 15:37:10
问题 Is there any method(didn't find in API) or solution to click on element with text? For example i have html: <div class="elements"> <button>Button text</button> <a href=#>Href text</a> <div>Div text</div> </div> And I want to click on element in which text is wrapped(Click on button inside .elements), like: Page.click('Button text', '.elements') Any solution? 回答1: You may use a XPath selector with page.$x(expression): const linkHandlers = await page.$x("//a[contains(text(), 'Some text')]"); if

How to select an option from dropdown select

陌路散爱 提交于 2019-11-26 11:20:20
问题 I can click the selector but my question is how to select one of the options from the dropdown list? await page.click(\'#telCountryInput > option:nth-child(4)\') Click the option using CSS selector does not work. For example, select a country code from a list like below, 回答1: Puppeteer v0.13.0 has page.select() method, which does exactly that. You just have to give it the value to select. So, assuming you have an <option value="my-value"> in your <select> : await page.select('#telCountryInput

Puppeteer: pass variable in .evaluate()

China☆狼群 提交于 2019-11-26 10:34:21
问题 I\'m trying to pass a variable into a page.evaluate() function in Puppeteer, but when I use the following very simplified example, the variable evalVar is undefined. I\'m new to Puppeteer and can\'t find any examples to build on, so I need help passing that variable into the page.evaluate() function so I can use it inside. const puppeteer = require(\'puppeteer\'); (async() => { const browser = await puppeteer.launch({headless: false}); const page = await browser.newPage(); const evalVar = \

网页应该如何录屏呢?

陌路散爱 提交于 2019-11-25 17:02:33
摘要: 网页应该如何录屏呢? 作者: Winty 原文: 用户行为录帧调研 Fundebug 经授权转载,版权归原作者所有。 关键点 首先,每一次会话都有一个唯一的session ID,这是串联起所有行为的纽带。 其次,用户行为又分成两个部分,其一是用户的操作,比如鼠标滑动,点击,页面滚动等,其二是页面的变化。这两者我们都统称为用户行为,记录在同一个队列中。 一开始的时候,系统会记录下初始的页面作为第一帧,这是唯一的一次完整页面记录。 针对用户操作,我们会记录事件的类型,鼠标位置等关键信息,保存到队列中。 针对页面变动,我们会起一个mutationObserve侦听页面的改动,每次只记录改动的部分,保存到队列中。 无论是事件还是页面改动,都是对等的一帧,每一帧都会有当前时间,与上一帧间隔时间等基本信息用户还原 一旦出错,SDK就把队列发送到监控系统,并清空当前队列。 还原端根据记录的行为队列,根据时间逐一播放出来。最终形成一个类似于视频的效果。 初步思路 方式一: 前端收集信息,首先,初始化的时候记录一个页面的初始状态,然后利用 MutationObserver 监听dom的改变事件,然后监听所有的鼠标事件、滚动事件等等所有的页面变化。 在合理的时机把这些信息队列上传到服务器,如页面出错时等。 后台分析前端收集到的信息,转为图片,然后形成"视频",或者用户行为栈。提供对应的调用