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.