Python 자동화 테스트 시리즈 [v1.0.1] [브라우저 자동 모드 시작]

4550 단어
실제 자동화 테스트에서 브라우저가 빈번하게 작동하고 닫히지 않도록 자동 모드로 실행할 수 있다. 코드 예시는 다음과 같다.
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
#   chrome Option  
chrome_options = Options()
#       
chrome_options.add_argument('--headless')
for i in range(100000):
    #          
    chrome_driver = webdriver.Chrome(options=chrome_options)
    #      
    chrome_driver.get("http://www.yialife.co.za/contact.html")
    chrome_driver.maximize_window()
    chrome_driver.find_element_by_class_name("xhl-button-text").click()
    #       
    current_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
    chrome_driver.find_element_by_id("messageText").send_keys("audio notification testing at " + current_time)
    time.sleep(1)
    chrome_driver.find_element_by_id("sendBtn").click()
    print(current_time)
    time.sleep(5)
    #     cookie
    chrome_driver.delete_all_cookies()
chrome_driver.quit()

좋은 웹페이지 즐겨찾기