Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

basics/hover.js cannot take snapshot without sleep for some time #12

Open
keegoo opened this issue Feb 20, 2019 · 1 comment
Open

basics/hover.js cannot take snapshot without sleep for some time #12

keegoo opened this issue Feb 20, 2019 · 1 comment

Comments

@keegoo
Copy link

keegoo commented Feb 20, 2019

Hi Team, nice examples!

basics/hover.js example

For me I have to add a sleep() function to make sure await page.screenshot({ path: 'hover.png' }) can capture the hover effect.

const puppeteer = require('puppeteer');

function sleep(ms) {
  return new Promise(resolve => {
    setTimeout(resolve, ms)
  })
}

(async () => {
  const browser = await puppeteer.launch()
  const page = await browser.newPage()
  await page.goto('https://soundcloud.com/')
  await page.hover('.playableTile__artwork')
  await sleep(1000)  // <-- sleep 
  await page.screenshot({ path: 'hover.png' })
  await browser.close()
})()

Is it only me have this issue? Is there anyway I can get rid of sleep() ?

Thanks!

[without sleep]
hover

[with sleep]
hover

@tnolet
Copy link
Member

tnolet commented Feb 22, 2019

@keegoo this is probably due to fade in animations. I get it on a lot of sites that have this behaviour. sleep() can work, but maybe using the .waitForSelector() with the "visible" flag can also work, i.e.

await page.waitForSelector('.play-button-bla-bla-bla-class', { visible: true })

did not test this yet...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants