puppeteer: wait N seconds before continuing to the next line

You can use a little promise function, function delay(time) { return new Promise(function(resolve) { setTimeout(resolve, time) }); } Then, call it whenever you want a delay. console.log(‘before waiting’); await delay(4000); console.log(‘after waiting’); If you must use puppeteer use the builtin waitForTimeout function. await page.waitForTimeout(4000) If you still want to use page.evaluate, resolve it after 4 … Read more

How to click on element with text in Puppeteer

Short answer This XPath expression will query a button which contains the text “Button text”: const [button] = await page.$x(“//button[contains(., ‘Button text’)]”); if (button) { await button.click(); } To also respect the <div class=”elements”> surrounding the buttons, use the following code: const [button] = await page.$x(“//div[@class=”elements”]/button[contains(., ‘Button text’)]”); Explanation To explain why using the text … Read more

How can I pass variable into an evaluate function?

You have to pass the variable as an argument to the pageFunction like this: const links = await page.evaluate((evalVar) => { console.log(evalVar); // 2. should be defined now … }, evalVar); // 1. pass variable as an argument You can pass in multiple variables by passing more arguments to page.evaluate(): await page.evaluate((a, b c) => … Read more

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

The timeout you specify here needs to be shorter than the default timeout. The default timeout is 5000 and the framework by default is jasmine in case of jest. You can specify the timeout inside the test by adding jest.setTimeout(30000); But this would be specific to the test. Or you can set up the configuration … Read more

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