get_screenshot_as_file --截图功能

from selenium import  webdriver

def get_screent_img(self):
""""页面截图功能,

os方法

https://www.cnblogs.com/saryli/p/4293690.html

  • os.path.abspath(path) : 返回绝对路径
  • os.path.basename(path): 返回文件名
  • os.path.dirname(path) : 返回文件路径

"""
file_path = os.path.dirname(os.path.abspath(".")) + './screenshots/'
# %Y-%m-%d_%H_%M_%S_
now = time.strftime('%Y-%m-%d_%H:%M:%S')
screen_name = file_path + now + '.png'
print(screen_name)
try:
self.driver.get_screenshot_as_file(screen_name)
logger.info('页面截图 %s,截图路径在: /screenshots/目录下' % self.driver.get_screenshot_as_file(screen_name))
except NameError as na:
logger.info("截图失败:%s" % na)
self.get_screent_img()

---------------------
作者:Sily_Z
来源:CSDN
原文:https://blog.csdn.net/Sily_Z/article/details/80989823
版权声明:本文为博主原创文章,转载请附上博文链接!

posted @ 2019-03-05 20:06  乖乖楠  阅读(2210)  评论(0编辑  收藏  举报