python+selenium 屏幕截屏


#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:\screenPicture2.png")
            print (result)
        except IOError as e:
            print (e)


    def tearDown(self):
        # 退出IE瀏覽器
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM