截屏方式一:
driver.save_screenshot('绝对路径\文件名.png')
截屏方式二:
driver.get_screenshot_as_file('绝对路径\文件名.png')
截屏方式三:
driver.get_screenshot_as_png()
截屏方式四:
driver.get_screenshot_as_base64()
示例代码:截取必应浏览器首页并保存
from selenium import webdriver
import base64
driver = webdriver.Chrome()
driver.get('https://cn.bing.com')
driver.save_screenshot(r'E:\软件测试学习\test\必应首页1.png')
driver.get_screenshot_as_file(r'E:\软件测试学习\test\必应首页2.png')
datas = driver.get_screenshot_as_png()
with open(r'E:\软件测试学习\test\必应首页3', 'wb') as file:
file.write(datas)
base64_datas = driver.get_screenshot_as_base64()
decode_datas = base64.b64decode(base64_datas)
with open(r'E:\软件测试学习\test\必应首页4', 'wb') as file2:
file2.write(decode_datas)
driver.quit()