有时候需要把一些浏览器当前窗口截图下来,比如操作抱错的时候。WebDriver类下.get_screenshot_as_file()方法可窗口截图,需要传入一个截图文件名的路径。window要用\\当做路径符
from selenium import webdriver import time dr = webdriver.Firefox() dr.get('https://www.baidu.com') dr.find_element_by_id('kw').send_keys('selenium') dr.find_element_by_id('su').click() time.sleep(2) dr.get_screenshot_as_file("D:\\test.png")