FabricioG
FabricioG

Reputation: 3320

Not clicking on element after class specifically called

For some reason I'm not able to click on an element that appears on a screen with puppeteer js. Here is the code:

  const getAllElements = await page.$$('._1Nk0C');

  for (let [i, link] of getAllElements.entries()) {
    try {
      await link.click();
      await sleep.sleep(4);
      await link.click('._1NHYN _3d86A Ddtb4');
    } catch (e) {
      console.error(e);
    }
  }

Here I find all elements with '._1Nk0C' It then clicks on the element which as it enlarge in forefront. await link.click(); I then try to click the button on screen. I can confirm this is on the screen.

await link.click('._1NHYN _3d86A Ddtb4');

Nothing happens. It doesn't error out just doesn't click on element. Am I missing something?

Upvotes: 0

Views: 27

Answers (1)

mbit
mbit

Reputation: 3013

elementHandle.click([options]) does not accept a selector as an argument. If you're trying to click on an element in the page based on its selector try:

await link.click();
await sleep.sleep(4);
await page.click(selector);

Upvotes: 1

Related Questions