方法:get_screenshot_as_file(filename)
# coding=UTF-8 #16.对当前浏览器窗口截屏 import sys reload(sys) sys.setdefaultencoding('utf8') from selenium import webdriver import unittest import time class Case16(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() def test_captureScreenInCurrentWindow(self): url = "https://www.sogou.com" self.driver.get(url) try: result = self.driver.get_screenshot_as_file(r"C:\Users\xxx\Desktop\screenPicture.png") print result except IOError,e: print e def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
注:Python的 IOErro错误主要是指要打开的文件不存在的错误提示