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

javascript - How to track pop-up modal on Puppeteer - Stack Overflow

programmeradmin2浏览0评论
const products = await page.$$('.product-list li .hover-overlay');

for (var a = 2; a <= products.length; a++) {
  await Promise.all([
    page.hover(`.product-list li:nth-child(${a}) .hover-overlay`),
    page.click(`.product-list li:nth-child(${a}) .hover-overlay`),
    page.waitForSelector('.modal', { visible: true }),
    page.waitForSelector('.save-btn', { visible: true }),
    page.click('.save-btn'),
  ])
}

this is the error

Error: No node found for selector: .save-btn

puppeteer : ^1.7.0

node : v9.4.0

const products = await page.$$('.product-list li .hover-overlay');

for (var a = 2; a <= products.length; a++) {
  await Promise.all([
    page.hover(`.product-list li:nth-child(${a}) .hover-overlay`),
    page.click(`.product-list li:nth-child(${a}) .hover-overlay`),
    page.waitForSelector('.modal', { visible: true }),
    page.waitForSelector('.save-btn', { visible: true }),
    page.click('.save-btn'),
  ])
}

this is the error

Error: No node found for selector: .save-btn

puppeteer : ^1.7.0

node : v9.4.0

Share Improve this question asked Aug 20, 2018 at 17:20 DennisDennis 231 gold badge1 silver badge3 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 2

Promise.all will let all the promises run to fulfillment simultaneously, so here you’re simultaneously hovering and clicking on a particular element, waiting for two selectors, and clicking on an element matching the last one. You can perform these actions in a sequence by using await inside the loop as well:

const products = await page.$$('.product-list li .hover-overlay');

for (const overlay of products.slice(2)) {
  await overlay.hover();
  await overlay.click();
  await page.waitForSelector('.modal', { visible: true });
  const button = await page.waitForSelector('.save-btn', { visible: true });
  await button.click();
  await page.waitForFunction('.modal', { hidden: true });
}

I’m using references to the elements themselves to avoid repeatedly searching for them. I’m assuming you call hover on the overlay before clicking because the page won’t register a click without hovering first; if that’s not the case, you can leave out the hover entirely.

发布评论

评论列表(0)

  1. 暂无评论