我正在尝试使用我的代码使用 puppeteer 单击按钮,但由于某种原因,始终无法找到该按钮(无效的选择器/错误:未找到选择器的节点)或 waitFor 过期,这是我的代码:
const puppeteer = require('puppeteer');
const product_url = "https://www.amazon.co.uk/Usoun-Multi-Angle-Heat-Vent-Adjustable-Compatible/dp/B086HNM8F7/ref=sr_1_7?crid=16VVWBHJOOAYE&keywords=laptop+stand+adjustable&qid=1645642193&sprefix=laptop+stand+adjustable%2Caps%2C75&sr=8-7"
async function givePage(){
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
return page;
}
async function buyNow(page){
await page.goto(product_url);
await page.waitFor(20000);
await page.click("button[class='a-button a-button-oneclick a-button-icon onml-buy-now-
button buybox-button-enhancement-size']", elem => elem.click());
}
async function checkout(){
var page = await givePage();
await buyNow(page);
}
checkout();