简体   繁体   中英

Are these 2 puppeteer functions equivalent?

Do these 2 pieces of code both select and and click the same element?

Are they practically equivalent?

await page.$eval('#loginForm > button', form => form.click());
const button = await page.$('#loginForm > button');
await button.click();

Not always.

The first code just uses Web-API HTMLElement.click() .

The second uses a more complicated way :

This method scrolls element into view if needed, and then uses page.mouse to click in the center of the element. If the element is detached from DOM, the method throws an error.

I've read in various issues that users had different effects from these approaches in the various page contexts. Sometimes one of them works properly while other does not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM