WebDriver提供了截图函数get_screenshot_as_file()来截取当前窗口。
from selenium import webdriver
from time import sleep
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")
driver.find_element_by_id('kw').send_keys('selenium')
driver.find_element_by_id('su').click()
sleep(5)
# 截取当前窗口,并指定截图图片的保存位置
driver.get_screenshot_as_file("D:selenium_img.png")
sleep(5)
driver.quit()
参考资料:http://www.testclass.net/selenium_python/get-screenshot/