8、webdriver的get_screenshot_as_file错误截图并保存到指定文件中

#!/usr/bin/env python
# coding=utf-8
from selenium import webdriver
import time
from selenium.common.exceptions import NoSuchElementException

driver = webdriver.Firefox()

driver.get("https://baidu.com")

# 捕捉百度输入框异常并截图
try:
    driver.find_element_by_id('xx').click()
except NoSuchElementException as msg:
    f_name = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))
    driver.get_screenshot_as_file('D:/' + f_name + '.png')
    print(msg)
    driver.quit()
发布了52 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/yijinaqingan/article/details/85307125
今日推荐