截图方法get_screenshot_as_file()注意点

 2023-09-05 阅读 100 评论 0

摘要:ef img_screenshot(self,Image_name):try:self.driver.get_screenshot_as_file('D:\workspace\thinksns\result\screenshot\fail\'+Image_name+'.jpg')except:self.log.error(u'截图失败:') get_screenshot_as_file()如
ef img_screenshot(self,Image_name):try:self.driver.get_screenshot_as_file('D:\workspace\thinksns\result\screenshot\fail\'+Image_name+'.jpg')except:self.log.error(u'截图失败:')

get_screenshot_as_file()如上述代码所示,截图保存的路径必须为绝对路径,如果上述写为相对路径截图会失败哦!切记

如果我们想在截的图名字上加上时间可以如下:

def img_screenshot(self,Image_name):try:now = time.strftime('%Y-%m-%d_%H-%M-%S') #截图的方法中不允许存在以下符号 / : * ? # ” < > |self.driver.get_screenshot_as_file('D:\workspace\thinksns\result\screenshot\fail\'+Image_name+now+'.png') #这里路径必须为绝对路径不然截图失败except:self.log.error(u'截图失败:')原本方法是这样写的time.strftime('%Y-%m-%d_%H:%M:%S') 但是因为截图的方法中不允许存在以下符号 / : * ? # ” < > |不然截图失败,所以只能将:改为-

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://808629.com/804.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 86后生记录生活 Inc. 保留所有权利。

底部版权信息