2

I am trying to save a screenshot from a website using Selenium with Python 3.6 (on Windows 10). When I use the get_screenshot_as_file() or get_screenshot_as_png() functions, I always get the following exception:

WebDriverException: unknown error: cannot get automation extension from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html

(Session info: chrome=60.0.3112.90)

(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64)

For example:

driver = webdriver.Chrome()
ref = 'http://google.com'
driver.get(ref)
driver.get_screenshot_as_png()

Is there a workaround, or another way to save the entire page as an image?

splinter
  • 3,727
  • 8
  • 37
  • 82

1 Answers1

2

I would recommend you to use save_screenshot() method instead of get_screenshot_as_png() method. save_screenshot() method takes an argument as the name of the screenshot along with the logical/absolute path. The following code block navigates to the URL and saves the screenshot as temp.png within a sub-directory named Screenshots which was created within my project scope.

from selenium import webdriver
driver = webdriver.Chrome(r'C:\Utility\BrowserDrivers\chromedriver.exe')
ref = 'http://google.com'
driver.get(ref)
driver.save_screenshot('./Screenshots/temp.png')
driver.quit()

Note that the Python Documentation specifies that there does exists some more methods() as follows:

  1. get_screenshot_as_png() : Gets the screenshot of the current window as a binary data.
  2. get_screenshot_as_file(filename) : Gets the screenshot of the current window.
  3. get_screenshot_as_base64() : Gets the screenshot of the current window as a base64 encoded string

Reference

You can find a detailed discussion in How to take screenshot with Selenium WebDriver

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352