I'm trying to find the corresponding code for puppeteer to automate a button press.
Example page: https://www.alternate.de/html/product/1685585
In a userscript it can be done easily via
document.getElementsByClassName("details-cart-button btn btn-primary btn-block btn-lg d-flex justify-content-center tp-button ")[0].click();
However im struggling to replicate the same behavior using puppeteer.
What I tried so far:
//Try 1: await page.click('a[class="details-cart-button btn btn-primary btn-block btn-lg d-flex justify-content-center tp-button "]'); //Try 2: await page.$eval('a[class^="details-cart-button"]', el => el.click()); //Try3: const form = await page.$('id#add-to-cart-form'); await form.evaluate( form => form.click() ); //Try4: await Promise.all([ await page.click('#add-to-cart-form > a.details-cart-button.btn.btn-primary.btn-block.btn-lg.d-flex.justify-content-center.tp-button') ]);
None of the methods seem to work sadly and I have no idea how to get it done.
Could someone be kind enough to point me in the right direction?
Thanks a lot in advance!
https://stackoverflow.com/questions/67377791/puppeteer-clicking-button-on-a-website-doesnt-work May 04, 2021 at 09:47AM
没有评论:
发表评论