zoukankan      html  css  js  c++  java
  • python selenium截取指定元素图片

    1.截取当前屏幕

        @property
        def getImage(self):
            '''
            截取图片,并保存在images文件夹
            :return: 无
            '''
            timestrmap = time.strftime('%Y%m%d_%H.%M.%S')
            imgPath = os.path.join(gl.imgPath, '%s.png' % str(timestrmap))
    
            self.driver.save_screenshot(imgPath)
            print  'screenshot:', timestrmap, '.png'

    2.截取当前元素

        def getElementImage(self,element):
            """
            截图,指定元素图片
            :param element: 元素对象
            :return: 无
            """
            """图片路径"""
            timestrmap = time.strftime('%Y%m%d_%H.%M.%S')
            imgPath = os.path.join(gl.imgPath, '%s.png' % str(timestrmap))
    
            """截图,获取元素坐标"""
            self.driver.save_screenshot(imgPath)
            left = element.location['x']
            top = element.location['y']
            elementWidth = left + element.size['width']
            elementHeight = top + element.size['height']
    
            picture = Image.open(imgPath)
            picture = picture.crop((left, top, elementWidth, elementHeight))
            timestrmap = time.strftime('%Y%m%d_%H.%M.%S')
            imgPath = os.path.join(gl.imgPath, '%s.png' % str(timestrmap))
            picture.save(imgPath)
            print  'screenshot:', timestrmap, '.png'

    期待你的加入:

    python|测试|技术交流 qq群:563227894

    python|测试|技术交流 qq群:563227894

    python|测试|技术交流 qq群:563227894

  • 相关阅读:
    flex布局
    媒体查询
    transform详细解释
    读取long类型数据
    Oracle中快速清空当前用户的所有表数据
    没有表头的csv文件怎么导入Kettle
    Kettle性能调优汇总
    oralce中特殊字符的查询
    数据的单值、多值、派生、简单、复合属性
    kettle学习
  • 原文地址:https://www.cnblogs.com/yhleng/p/9294707.html
Copyright © 2011-2022 走看看