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