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/
原文地址:https://www.cnblogs.com/studyddup0212/p/9034524.html
时间: 2024-10-12 23:43:29