selenium 截图实例封装

本贴最后更新于 592 天前,其中的信息可能已经事过景迁

from selenium import webdriver
from time import sleep, strftime, localtime, time
from selenium.webdriver.common.by import By
from Common import project_path

class Test:
    def __init__(self, Test_driver):
        self.driver = Test_driver

    def save_screenshot(self):
        file_name = strftime("%Y%m%d-%H%M%S", localtime(time())) + ".png"
        # self.driver.save_screenshot(project_path.Test_screenshot + "\\" + file_name) #移动到指定文件夹中
        self.driver.save_screenshot(file_name)
        driver.quit()

    def login(self):
        element = driver.find_element(By.ID, value="kw")
        element.send_keys("自动化测试")
        sleep(1)
        self.save_screenshot()


if __name__ == '__main__':
    driver = webdriver.Chrome()  # 打开浏览器
    driver.get("https://www.baidu.com/")
    Test(driver).login()
  • Web
    21 引用 • 10 回帖
  • Selenium
    31 引用 • 23 回帖 • 1 关注
1 回帖
请输入回帖内容 ...
  • Rui

    新人发帖,当个工具、学习