在测试过程中经常需要截取屏幕操作,webdriver提供了get_screenshot_as_file()方法满足截屏需求,具体实例如下:
from selenium import webdriver
from time import sleep
driver = webdriver.Firefox()
driver.get("https://www.baidu.com")
driver.find_element_by_id("kw").send_keys("python")
driver.find_element_by_id("su").click()
sleep(30)
driver.get_screenshot_as_file("E:\\baidu.png")
driver.quit()