URL : https://auto.ru/catalog/cars/all/?page_num=1
JS code:
const puppeteer = require('puppeteer');
(async () => {
try {
const browser = await puppeteer.launch({args: ['--no-sandbox']});
const page = await browser.newPage();
await page.goto('https://auto.ru/catalog/cars/all/?page_num=1', {waitUntil: 'networkidle2'});
await page.click('#confirm-button');
await page.waitFor(1000);
await page.screenshot({path: './data/example.png'});
await browser.close();
} catch (err) {
console.error(err);
}
})();
When I run this code there are no errors but also there is no click, I stay at the same page.
How can I make a click to the left blue button with Puppeteer (open the URL with incognito mode to see the buttons)?
It is working fine. You just need to wait for the navigation to complete before taking the snapshot. Also, always make sure the element appears before trying to click on it:
await page.waitForSelector("#confirm-button");
await Promise.all([
page.click('#confirm-button'),
page.waitForNavigation()
]);
await page.screenshot({path: './data/example.png'});