日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python selenium截图_python+selenium截图操作样例

發布時間:2025/3/12 python 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python selenium截图_python+selenium截图操作样例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#?-*-?coding:utf-8?-*-

#?explain?:?截圖操作

import?os,?time

class?Picture:

"""

截圖操作

分為正常的操作截圖truepicture

和異常的操作截圖errorpicture

"""

def?__init__(self,?driver,?path):

"""

:type?driver:?selenium.webdriver.remote.webdriver.WebDriver

:param?driver?WebDriver對象

:param?path?截圖存放位置

"""

self.__driver?=?driver

self.__path?=?path

def?__picturelocation(self):

#?path?=?Primary.readini.getvalue("picture",?"picturelocation")

path?=?self.__path

if?not?os.path.exists(path):??#?判斷圖片位置是否存在,不存在則先創建

os.makedirs(path)

picdatetime?=?time.strftime("%Y-%m-%d",?time.localtime())??#?文件名為日期

#?正確圖片目錄

turepath?=?os.path.join(path,?picdatetime?+?'/turepicture')??#?正確圖片位置

if?not?os.path.exists(turepath):

os.makedirs(turepath)

#?錯誤圖片目錄

errorpath?=?os.path.join(path,?picdatetime?+?'/errorpicture')?#?錯誤圖片位置

if?not?os.path.exists(errorpath):

os.makedirs(errorpath)

return?[turepath,?errorpath]

def?truepicture(self,?picusername):

"""

正常操作的截圖

文件的保存位置在配置文件的turepicture

:param?picusername:??圖片的文件名稱

"""

turepath?=?self.__picturelocation()[0]

#?通過路徑來拼接圖片存放路徑

self.__driver.get_screenshot_as_file(turepath?+?os.sep?+?picusername?+

time.strftime("%Y-%m-%d%H%M",?time.localtime())?+?'.png')

def?errorpicture(self,?picusername):

"""

出現錯誤的截圖操作

文件的保存位置在配置文件的errorpicture

:param?picusername:??圖片的文件名稱

"""

#?通過路徑來拼接圖片存放路徑

errorpath?=?self.__picturelocation()[1]

#?截圖

self.__driver.get_screenshot_as_file(errorpath?+?os.sep?+?picusername?+

time.strftime("%Y-%m-%d%H%M",?time.localtime())?+?'.png')

UI自動化截圖操作簡單樣例

總結

以上是生活随笔為你收集整理的python selenium截图_python+selenium截图操作样例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。