Selenium WebDriver-截屏操作
#encoding=utf-8 import unittest import time import chardet from selenium import webdriver class VisitSogouByIE(unittest.TestCase): def setUp(self): #启动IE浏览器 #self.driver = webdriver.Firefox(executable_path = "e:\\geckodriver") self.driver = webdriver.Ie(executable_path = "e:\\IEDriverServer") def test_captureScreenInCurrentWindow(self): url = "http://www.sohu.com" # 访问搜狗首页 self.driver.get(url) try: ''' 调用get_screenshot_as_file(filename)方法,对浏览器当前打开页面 进行截图,并保为E盘下的screenPicture.png文件。 ''' result = self.driver.get_screenshot_as_file(r"e:\screenPicture.png") print result except IOError, e: print e def tearDown(self): # 退出IE浏览器 self.driver.quit() if __name__ == '__main__': unittest.main()