最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Puppeteer selector based on attribute error - Stack Overflow

programmeradmin6浏览0评论

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.

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.

Share Improve this question edited Oct 29, 2018 at 18:31 Grant Miller 29.1k16 gold badges155 silver badges168 bronze badges asked Oct 29, 2018 at 8:32 Jessie ChanJessie Chan 111 gold badge1 silver badge2 bronze badges 1
  • Can you explain what you mean by it won't work? – Md. Abu Taher Commented Oct 29, 2018 at 8:39
Add a ment  | 

2 Answers 2

Reset to default 4

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"]');

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.

发布评论

评论列表(0)

  1. 暂无评论