Puppeteer in NodeJS reports ‘Error: Node is either not visible or not an HTMLElement’

Try doing this: await button.evaluate(b => b.click()); instead of await button.click(); The difference is that button.evaluate(b => b.click()) runs the JavaScript HTMLElement.click() method on the given element in the browser context, which will fire a click event on that element even if it’s hidden, off-screen or covered by a different element, whereas button.click() clicks using … Read more

Collect elements by class name and then click each one – Puppeteer

Iterating puppeteer async methods in for loop vs. Array.map()/Array.forEach() As all puppeteer methods are asynchronous it doesn’t matter how we iterate over them. I’ve made a comparison and a rating of the most commonly recommended and used options. For this purpose, I have created a React.Js example page with a lot of React buttons here … Read more

Puppeteer – Protocol error (Page.navigate): Target closed

What “Target closed” means When you launch a browser via puppeteer.launch it will start a browser and connect to it. From there on any function you execute on your opened browser (like page.goto) will be send via the Chrome DevTools Protocol to the browser. A target means a tab in this context. The Target closed … Read more

Completely disable auto run of Jest test runner in Visual Studio Code editor

For orta.vscode-jest extension, I added the configuration below in settings.json. You can open settings.json by doing Command + Shift + P (Ctrl + Shift + P on Windows), typing settings JSON and selecting Preferences: Open User Settings (JSON). “jest.autoRun”: { “onStartup”: [] } Or you can simply add: “jest.autoRun”: {} If you want to run … Read more

Bypassing CAPTCHAs with Headless Chrome using puppeteer

Try generating random useragent using this npm package. This usually solves the user agent-based protection. In puppeteer pages can override browser user agent with page.setUserAgent var userAgent = require(‘user-agents’); … await page.setUserAgent(userAgent.random().toString()) Additionally, you can add these two extra plugins, puppeteer-extra-plugin-recaptcha – Solves reCAPTCHAs automatically, using a single line of code: page.solveRecaptchas() NOTE: puppeteer-extra-plugin-recaptcha uses … Read more

How to delete existing text from input using Puppeteer?

You can use page.evaluate to manipulate DOM as you see fit: await page.evaluate( () => document.getElementById(“inputID”).value = “”) However sometimes just manipulating a given field might not be enough (a target page could be an SPA with event listeners), so emulating real keypresses is preferable. The examples below are from the informative issue in puppeteer’s … Read more

Puppeteer: How to submit a form?

If you are attempting to fill out and submit a login form, you can use the following: await page.goto(‘https://www.example.com/login’); await page.type(‘#username’, ‘username’); await page.type(‘#password’, ‘password’); await page.click(‘#submit’); await page.waitForNavigation(); console.log(‘New Page URL:’, page.url());

Puppeteer wait for all images to load then take screenshot

There is a built-in option for that: await page.goto(‘https://www.digg.com/’, {“waitUntil” : “networkidle0”}); networkidle0 – consider navigation to be finished when there are no more than 0 network connections for at least 500 ms networkidle2 – consider navigation to be finished when there are no more than 2 network connections for at least 500 ms. Of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)