Puppeteer

Using puppeteer how do you get all child nodes of a node?

China☆狼群 提交于 2021-02-19 07:54:47
问题 I'm having trouble finding a way to iterate subnodes of a given node in puppeteer. I do not know the html structure beforehand, just the id of the parent element. var elemId = "myelemid"; const doc = await page._client.send('DOM.getDocument'); const node = await page._client.send('DOM.querySelector', { nodeId: doc.root.nodeId, selector: '#' + elemId }); //node.children empty //node['object'].children empty //try requesting childnodes var id = node.nodeId; var childNodes = await page._client

Hover on element and getComputedStyle in Node.js using Puppeteer?

我只是一个虾纸丫 提交于 2021-02-19 05:31:38
问题 I want to hover on some element, let say document.getElementById("abc") and find its hover computed style. How should I do it in Node.js using Puppeteer? 回答1: You can use the following solution to iterate and hover over certain elements to obtain the computed style: const elements = await page.$$('.abc'); const data = []; for (let i = 0; i < elements.length; i++) { await elements[i].hover(); data.push(await page.evaluate(element => window.getComputedStyle(element), elements[i])); } console

Hover on element and getComputedStyle in Node.js using Puppeteer?

自作多情 提交于 2021-02-19 05:31:16
问题 I want to hover on some element, let say document.getElementById("abc") and find its hover computed style. How should I do it in Node.js using Puppeteer? 回答1: You can use the following solution to iterate and hover over certain elements to obtain the computed style: const elements = await page.$$('.abc'); const data = []; for (let i = 0; i < elements.length; i++) { await elements[i].hover(); data.push(await page.evaluate(element => window.getComputedStyle(element), elements[i])); } console

Passing a thunk to puppeteer's $.eval

时光怂恿深爱的人放手 提交于 2021-02-19 02:39:29
问题 The function setValue receives a value and returns a function. Inside the second function I'm trying to console log the value of value but I get Error: Evaluation failed: ReferenceError: value is not defined My code bellow. It can be tested on try-puppeteer, just copy and paste my code and remove the require statement. const puppeteer = require('puppeteer'); (async () => { const USERNAME = 'helloworld'; const setValue = (value) => (input) => { console.log(value) }; const browser = await

Getting DOM node text with Puppeteer and headless Chrome

主宰稳场 提交于 2021-02-18 10:15:51
问题 I'm trying to use headless Chrome and Puppeteer to run our Javascript tests, but I can't extract the results from the page. Based on this answer, it looks like I should use page.evaluate(). That section even has an example that looks like what I need. const bodyHandle = await page.$('body'); const html = await page.evaluate(body => body.innerHTML, bodyHandle); await bodyHandle.dispose(); As a full example, I tried to convert that to a script that will extract my name from my user profile on

Getting DOM node text with Puppeteer and headless Chrome

£可爱£侵袭症+ 提交于 2021-02-18 10:15:30
问题 I'm trying to use headless Chrome and Puppeteer to run our Javascript tests, but I can't extract the results from the page. Based on this answer, it looks like I should use page.evaluate(). That section even has an example that looks like what I need. const bodyHandle = await page.$('body'); const html = await page.evaluate(body => body.innerHTML, bodyHandle); await bodyHandle.dispose(); As a full example, I tried to convert that to a script that will extract my name from my user profile on

Handling network errors with Puppeteer

可紊 提交于 2021-02-18 08:11:20
问题 Has anyone ever tried to handle network connexion errors with Puppeteer ? I tried by launching a random page and checking if I receive no errors until it works ( this try is in a for loop ) : try{ responseAwait = await page1.goto('https://www.residentadvisor.net/dj.aspx?country=01') } catch (err) { console.log('Page load fail : '+ err) if (err == 'Error: net::ERR_INTERNET_DISCONNECTED' || err == 'Error: net::ERR_NETWORK_CHANGED' || err == 'Error: net::ERR_NAME_NOT_RESOLVED'){ let

changing the value of attributes using puppeteer

前提是你 提交于 2021-02-16 09:15:45
问题 I have an element 'input[name=startdate]' with an attribute 'value="2018-06-20"' instead of using puppeteer to interact with the calendar that is used to change the date, is there anyway I can use puppeteer to set the value instead? something like... let newDate = '2018-01-01' value.innerHTML = newDate 回答1: I was able to figure it out and I'm posting it here in case anyone else has the same problem. await page.$eval('input[name=startdate]', e => e.setAttribute("value", "2018-01-01")) If you

changing the value of attributes using puppeteer

狂风中的少年 提交于 2021-02-16 09:15:25
问题 I have an element 'input[name=startdate]' with an attribute 'value="2018-06-20"' instead of using puppeteer to interact with the calendar that is used to change the date, is there anyway I can use puppeteer to set the value instead? something like... let newDate = '2018-01-01' value.innerHTML = newDate 回答1: I was able to figure it out and I'm posting it here in case anyone else has the same problem. await page.$eval('input[name=startdate]', e => e.setAttribute("value", "2018-01-01")) If you

puppeteer being redirected when browser is not

偶尔善良 提交于 2021-02-11 14:25:12
问题 Attempting to test page https://publicindex.sccourts.org/anderson/publicindex/ When navigating with standard browser to the page, the navigation ends at the requested page (https://publicindex.sccourts.org/anderson/publicindex/) with the page displaying an "accept" button. However, when testing with puppeteer in headless mode, the request is redirected to https://publicindex.sccourts.org. I have a rough idea of what is occuring, but can not seem to prevent the redirection to https:/