1

If I try to click an element like this I get an error:

const handle = await page.$('.days-label.col-md-12.desktop div:nth-child(1)');
await handle.click();

However if I click it like this it works:

await page.$eval('.days-label.col-md-12.desktop div:nth-child(1)', el => el.click()); 

I tried fixing it by waiting for selector and navigation, but it's still the same error:

await page.waitForSelector('.days-label.col-md-12.desktop div:nth-child(1)');
const handle = await page.$('.days-label.col-md-12.desktop div:nth-child(1)');
await Promise.all([
    page.waitForNavigation(),
    handle.click(),
]);
GeoCap
  • 445
  • 4
  • 10
  • 1
    Why not use the one that works? This behavior is [known](https://stackoverflow.com/a/66537619/6243352). – ggorlen Dec 20 '21 at 18:53

1 Answers1

0

waitForSelector() returns <Promise<?ElementHandle>>:

const handle = await page.waitForSelector(
  '.days-label.col-md-12.desktop div:nth-child(1)'
)
await Promise.all([
    page.waitForNavigation(),
    handle.click(),
])
AnthumChris
  • 6,885
  • 2
  • 22
  • 47