3

When i tried to take screenshot of a webpage using selenium in python, i get error message selenium.common.exceptions.TimeoutException: Message: timeout: Timed out receiving message from renderer: 10.000.

Code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
indi_url = 'http://www.google.com'
options = Options()
options.add_argument("disable-infobars")
options.add_argument("--start-maximized")
options.add_argument("--disable-popup-blocking")
options.add_argument("disable-popup-blocking")
options.add_argument("--disable")
driver = webdriver.Chrome(options=options)
driver.get(indi_url)
driver.implicitly_wait(30)
driver.save_screenshot("new.png")

Error message:

Screenshot of error message

I'm using Chrome version 73, chromedriver version 73.

Note: code was working fine (ie.screenshot)in lower version of chrome and chrome driver.

Help me out in fixing this issue for new version of chrome driver.

Thanks in advance

Yakeshraj M
  • 31
  • 1
  • 3

2 Answers2

0

As the error shows, your filename for screenshot does not match the template extensions .png

Here is an example how to make a screenshot.

Java:

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(".\\Screenshots\\example_screenshot.png"));

Python:

driver.save_screenshot("screenshot.png")
Infern0
  • 2,565
  • 1
  • 8
  • 21
  • OP is using _Python_ possibly you have to refactor the _Java_ code into _Python_. – undetected Selenium Mar 26 '19 at 07:49
  • @Infern0 that won't be the issue, i guess because i have tried the same before, it worked fine before. And getting the same error msg using "driver.screenshot("screenshot.png")" – Yakeshraj M Mar 27 '19 at 01:37
0

This error message...

  UserWarning: name used for saved screenshot does not match file type. It should end with a .png extension
"type. It should end with a .png extension", UserWarning)

...implies that the Selenium-Python client encountered an issue while invoking get_screenshot_as_file() method.


get_screenshot_as_file()

get_screenshot_as_file() saves a screenshot of the current window to a PNG image file. Returns False if there is any IOError, else returns True. Use full paths in your filename.

  • Args:
    • filename: The full path you wish to save your screenshot to. This should end with a .png extension.
  • Usage:

    driver.get_screenshot_as_file('/Screenshots/foo.png')
    
  • Defination:

    if not filename.lower().endswith('.png'):
        warnings.warn("name used for saved screenshot does not match file "
                      "type. It should end with a `.png` extension", UserWarning)
    png = self.get_screenshot_as_png()
    try:
        with open(filename, 'wb') as f:
            f.write(png)
    except IOError:
        return False
    finally:
        del png
    return True
    

Analysis

As per the snapshot of the error stack trace:

snapshot

You have used the command as:

driver.get_screenshot_as_file('new.jpeg')

The issues were:

  • The filename didn't end with .png
  • The desired full path of your filename wasn't provided.

Even if you desire to use save_screenshot() this method in-turn invokes get_screenshot_as_file(filename)


Solution

Create a directory within your project as Screenshots and provide the absolute path of the filename you desire for the screenshot while invoking either of the methods as follows:

  • driver.get_screenshot_as_file("./Screenshots/YakeshrajM.png")
  • driver.save_screenshot("./Screenshots/YakeshrajM.png")

Update

Currently GAed Chrome v73 have some issues and you may like to downgrade to Chrome v72. You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • @YakeshrajM Did you get a chance to look into this solution? – undetected Selenium Mar 29 '19 at 04:41
  • facing same issue still.. As i already mentioned that code was working good with previous version of chrome and chrome driver and i was able to save the screenshots in '.jpg' format itself.. '.png' extension is just user warning message, which can be neglible. As already told by Ryan Bowden it is an open issue in chrome and they are trying to fix it. So waiting for the fix eagerly. – Yakeshraj M Mar 30 '19 at 16:59
  • @YakeshrajM Checkout the answer update and let me know the status. – undetected Selenium Mar 30 '19 at 17:01