How do I view the "Screenshot: available via screen"? How do I view the "Screenshot: available via screen"? selenium selenium

How do I view the "Screenshot: available via screen"?


Run the program in a try block and when the error occur take the screenshot using save_screenshot

Eg :

driver = webdriver.PhantomJS()driver.set_window_size(1920,1080)try:    driver.get('http://whatsmyuseragent.com/')except Exception,e:    driver.save_screenshot('screenshot.png')driver.close()

This will give you the screenshot during that momentImage will be saved at the working of your script


So - what "screen" are they talking about?

My exception looks like this:

  File "/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response    raise exception_class(message, screen, stacktrace)WebDriverException: Message: {"errorMessage":"Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: \"script-src 'self' connect.facebook.net cdn.ravenjs.com www.google-analytics.com banhang.shopee.vn chat.shopee.vn cdn.shopee.vn\".\n","request":{"objectName":"","statusCode":200,"headers":{"Cache":"no-cache","Content-Type":"application/json;charset=UTF-8"}}}Screenshot: available via screen

Take a look at the line: raise exception_class(message, screen, stacktrace), so the screen here means the variable screen:

>>> screenu'iVBORw0KGgoAAAANSUhEUgAABVYAAAMACAYAAADPPjzCAAAACXBIWXMAAAsTAAALEwEAmpwYAAAgAElE ...'

I don't know a quick way to show the screenshot, but screen looks like the image data that you can save to a file then view it.


I found that I can get the actual screenshot returned by the exception using the following (python3).

try:    ...except ElementNotVisibleException as e:    with open("imageToSave.png", "wb") as fh:        fh.write(base64.decodebytes(e.screen.encode()))

The driver.save_screenshot() function creates a new screenshot at a time later than when the exception occurred.