sayan
sayan

Reputation: 109

Puppeteer button not clicking

I can't seem to get a button to be clicked using puppeteer. Here is my code and below is as screenshot of the DOM. Note that I'm able to type the email just fine and the correct button element is selected but I can't get it to click it.

  const form = await page.$('[action="https://deadstock.us6.list-manage.com/subscribe/post?u=be9b719d1c345d54269781365&id=5534002567"]');
  const email = await form.$('#mce-EMAIL');
  const sub = await form.$('#mc-embedded-subscribe');
  await email.type(MyData[row].email);
  await sub.click;

enter image description here

Upvotes: 1

Views: 253

Answers (1)

theDavidBarton
theDavidBarton

Reputation: 8841

If you check the length of $$('#mc-embedded-subscribe') you can see there are more elements with the very same selector. So you need to select all of them first with page.$$, then you need to click on the 1st one, by selecting the index [0]. And you need to use elementHandle.click(), your click was missing the parenthesis.

  const sub = await form.$$('#mc-embedded-subscribe');
  ...
  await sub[0].click();

Upvotes: 1

Related Questions