3

We've tested this code in both iOS and Windows. In iOS, it saves as expected in the base directory of the .py file. However, when running on Windows, the screenshot does not save anywhere on the machine. The code for taking the screenshot is:

def test_python_webpage(self):
    driver = self.driver
    driver.maximize_window()
    driver.get(self.base_url + "/")
    driver.get_screenshot_as_file('base_url.png') 

Any thoughts on why this file isn't saving when executed on a Windows machine, but working fine on iOS?

Note: This is happening with all 3 browsers (IE 11, Chrome 38.0.2125.111, and FF). I'm working with PyCharm 3.4.1 to execute the scripts.

Brenda
  • 247
  • 1
  • 4
  • 14
  • What about using `driver.save_screenshot()` instead? Also see: http://stackoverflow.com/questions/8900073/webdriver-screenshot. – alecxe Nov 07 '14 at 20:36
  • No, that didn't work either. I tried it first, then driver.get_screenshot_as_png(). – Brenda Nov 07 '14 at 20:41
  • Do you see any errors? Do you see a screenshot being saved near the script you run (same directory)? What if you specify a full path instead of just a filename? Thanks. – alecxe Nov 07 '14 at 20:42
  • No, no errors whatsoever. It doesn't even seem to do anything when I execute the test. I have even adjusted the name to include the full path. – Brenda Nov 07 '14 at 20:46
  • Okay, what selenium package version are you using, what browser (and it's version)? – alecxe Nov 07 '14 at 21:16
  • The Selenium WebDriver binding that I'm using for Python is 2.44. I'm on a Windows 7 (64 bit) machine (service pack 1). My coworker used the same exact code on his Mac and it saved beautifully. – Brenda Nov 07 '14 at 21:23
  • Good, but what browser (and what version) are you using? Does switching the browser help? (e.g. from ff to chrome, or to ie) – alecxe Nov 07 '14 at 21:25
  • Sorry. This is happening with all 3 browsers (IE 11, Chrome 38.0.2125.111, and FF). I'm working with PyCharm 3.4.1 to execute the scripts. – Brenda Nov 07 '14 at 21:29
  • Thanks for the info, Brenda. Please edit the question and include all that information I've asked you about into the question itself. This would help others to help you. – alecxe Nov 07 '14 at 21:30
  • you've searched the entire drive for the file base_url.png? Could it be as simple as permission error on the folder? Can you specify a full path that you know you have access to? – DMart Jan 21 '15 at 23:13
  • I'd first check the permissions, you might be needing administrator privileges to save on that directory. – user1336321 Feb 19 '15 at 12:08

1 Answers1

1

Try this snippet which is in Python

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.google.com/')
browser.save_screenshot('screenshot.png')
browser.quit()
  • I started using `self.browser.get_screenshot_as_png('screenshot.png')` and it is working as hoped. Thanks! – Brenda Mar 19 '15 at 16:43