2

I have done the following:

from selenium import webdriver
#Save a screenshot from spotify.com in current directory
DRIVER = 'chromedriver'
driver = webdriver.Chrome(DRIVER)
driver.get('https://www.youtube.com/watch?v=xzLu9AnuDAw&start=40&hd=0')
driver.save_screenshot('my_screenshot.png')
driver.quit()

The issue is that it takes the screenshot while the video is still loading at that frame(in this case of 40 seconds). I need screenshots of youtube at certain time frames.

I know this method takes screenshot of the website, and somehow the loading of youtube website gets completed before the video is loaded.

Is there a way that I can instruct selenium to wait for, say 2 seconds, before capturing the screenshot?

rj dj
  • 260
  • 1
  • 5
  • 22
  • Possible duplicate of [How can I make a time delay in Python?](https://stackoverflow.com/questions/510348/how-can-i-make-a-time-delay-in-python) – Andersson May 02 '18 at 05:15

1 Answers1

6
import time
time.sleep(2) # sleep for 2 seconds
driver.save_screenshot('my_screenshot.png')
Shivam Singh
  • 1,584
  • 1
  • 10
  • 9