Jessie Chan
Jessie Chan

Reputation: 11

Puppeteer selector based on attribute error

I want to select input based on type equal to 'submit'. Why does this selector not work?

await page.click('input[type="submit"')

For:

<input type="submit" value="submit" />

It's a typical selector in j@uery.

Upvotes: 1

Views: 12269

Answers (2)

Grant Miller
Grant Miller

Reputation: 29019

You may need to wait for the element specified by the selector to be added to the DOM and visible before attempting to click it:

await page.waitForSelector('input[type="submit"]', {
  visible: true,
});

Additionally, as AJC24 pointed out, you are in fact missing a right square bracket ], so the selector must be accurate before passing it to page.click():

await page.click('input[type="submit"]');

Upvotes: 4

AJC24
AJC24

Reputation: 3336

Looks like you have a typo in your selector to me. It should be:

await page.click('input[type="submit"]');

You were missing the ] character at the end of your selector.

Upvotes: 1

Related Questions