selenium - webdriver - 截图方法

selenium - webdriver - 截图方法get_screenshot_as_file()

WebDriver提供了截图函数get_screenshot_as_file()来截取当前窗口。

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

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/keyword-event/ 

你可能感兴趣的:(自动化)