Forums

Problem with chromedirver: driver.save_screenshot(name)

Hi there! when i apply screenshot in a task with chromedriver, i get usually the next error, but when i run from bash it runs always normal. Someone know how to fix it?

Traceback (most recent call last):
  File "/home/clau2020/scraping_bi.py", line 42, in <module>
    driver.save_screenshot(name)
  File "/home/clau2020/.virtualenvs/andy_campa/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 1055, in save_screenshot
    return self.get_screenshot_as_file(filename)
  File "/home/clau2020/.virtualenvs/andy_campa/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 1032, in get_screenshot_as_file
    png = self.get_screenshot_as_png()
  File "/home/clau2020/.virtualenvs/andy_campa/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 1064, in get_screenshot_as_png
    return base64.b64decode(self.get_screenshot_as_base64().encode('ascii'))
  File "/home/clau2020/.virtualenvs/andy_campa/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 1074, in get_screenshot_as_base64
    return self.execute(Command.SCREENSHOT)['value']
  File "/home/clau2020/.virtualenvs/andy_campa/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/clau2020/.virtualenvs/andy_campa/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: session deleted because of page crash
from tab crashed
  (Session info: headless chrome=78.0.3904.70)
  (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 5.4.0-1020-aws x86_64)

[edited by admin: formatting]

hi there, that is a weird one. Does this happen every time? Or do you mean this is triggered when you script sometimes errors? if that is the case, could it be that this particular error just crashed the whole browser?

Hi, it happens when i automize it in task, if i run it in bash console by myself it runs normal

Then you need to make sure that you are running it in the same environment (Python version/virtualenv) that you are using in the console. Also make sure that you are following the best practices like the example code here: https://www.pythonanywhere.com/forums/topic/27202/#id_post_78144