https://pptr.dev/ puppeteer
https://blog.appsignal.com/2023/02/08/puppeteer-in-nodejs-common-mistakes-to-avoid.html
Bear in mind that if click() triggers a navigation event and there's a separate page.waitForNavigation() promise to be resolved, you may end up with a race condition that yields unexpected results. The correct pattern for click and wait for navigation is the following
# M 1
const navigationPromise = page.waitForNavigation();
await page.click("#submit");
await navigationPromise;
# M 2
await Promise.all([
page.waitForNavigation(),
page.click("#submit"),
]);
const [response] = await Promise.all([
page.waitForNavigation(waitOptions),
page.click(selector, clickOptions),
]);
HTMLElement.click()
await page.goto(url);
await elementHandle.click();
await page.click('input[type=submit]');
await page.waitForNavigation();
await page.setDefaultNavigationTimeout(0);
process.exit(0);
// frame有点类似page
elementHandle = await page.waitForSelector(selector, {visible: true})
elementHandle = await page.waitForSelector(selector) 返回: <Promise<ElementHandle>>
elementHandle = await page.$(selector) 返回: <Promise<?ElementHandle>>
elementHandle = await page.$$(selector) 返回: <Promise<Array<ElementHandle>>>
elementHandle = await page.evaluateHandle();
element = await page.$eval();
// 获取Dom节点属性
text = await page.evaluate(el => el.textContent, elementHandle);
text = await elementHandle.evaluate(el => el.textContent);
element = await page.evaluate(() => {
return document.querySelector(selector);
return document.querySelector(selector).textContent;
});