selenium之截图

Posted yiruiwan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了selenium之截图相关的知识,希望对你有一定的参考价值。

下面和大家分享一下,ui自动化中截图方法。

代码如下:

def  screen_shot(self):

current_time=datatime.fromtimestamp(int(time.time()))  #获取当前时间

self.driver.sava_screenshot(os.path.join(IMG_PATH,current_time+‘png‘))    #调用sava_screenshot方法,将报错截图存放在指定目录

获取根目录py文件:

ROOT_PATH=os.path.dirname(os.path.abspath(__file__))  #获取项目路径

LOG_PATH=os.path.join(ROOT_PATH,‘LOG‘)  #创建log目录

if not  os.path.exists(LOG_PATH):

        os.mkdir(LOG_PATH)

IMG_PATH=os.path.join(LOG_PATH,‘img‘)  #创建img文件夹

if  not os.path.exists(IMG_PATH):

            os.mkdir(IMG_PATH)

 

以上是关于selenium之截图的主要内容,如果未能解决你的问题,请参考以下文章