屏幕截图用到的方法:
方法1:save_screenshot()
该方法直接保存当前屏幕截图到当前脚本所在的文件位置
示例:
脚本:
#!_*_ coding:UTF-8 _*_
from find_element.capability import driver
driver.find_element_by_xpath('//*[@text="安检测速"]').click()
driver.save_screenshot('anjian.png') #屏幕截图,保存到当前脚本所在的文件夹,命名为anjian.png
方法2:get_screenshot_os_file(self,filename)
该方法将截图保存到指定的文件夹路径
示例:
脚本:
#!_*_ coding:UTF-8 _*_ from find_element.capability import driver driver.find_element_by_xpath('//*[@text="安检测速"]').click() # 屏幕截图,保存指定文件夹时,需要确保对应的文件夹已创建,否则无法保存成功 driver.get_screenshot_as_file(u'F:\\wifibanlv\\find_element\\image\\anjian01.png')
注意:如果指定路径出现中文字符时,需要加上u’文件路径’进行转码