TA的每日心情 | 无聊 4 天前 |
---|
签到天数: 530 天 连续签到: 2 天 [LV.9]测试副司令
|
1测试积点
各位好
我的程序在跑到一半抱错时仍会在背景执行
这是因为线程没有被删除吗
因为我目前都是把 driver.quit() 这种挂在程式码的最后边
所以他得要全部流程都跑对才有办法关闭
想请问我该如何在程序失败时将线程完全关闭()
谢谢
- from datetime import datetime
- from selenium import webdriver
- import threading
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.wait import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- from selenium.webdriver.chrome.service import Service
- from selenium.webdriver.chrome.options import Options
-
- def selenium_mult():
- chrome_options = Options()
- chrome_options.add_argument("--headless")
- ser=Service('./chromedriver')
- driver = webdriver.Chrome(service = ser,options=chrome_options)
- driver.set_window_size(540,480)
- driver.get('https:/website')
-
- WebDriverWait(driver,10,1).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="btn"]/div/div[3]/button[1]')))
- driver.find_element(By.XPATH, '//*[@id="btn"]/div/div[3]/button[1]').click() #click button 1
- Ftime = datetime.now()
-
- WebDriverWait(driver,30,1).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="btn"]/div/div[2]/div[1]/div[6]/div')))
- driver.find_element(By.XPATH, '//*[@id="btn"]/div/div[2]/div[1]/div[6]/div').click() #click button 2
- driver.quit()
- if __name__ == '__main__':
- for i in range(5):
- t = threading.Thread(target=selenium_mult)
- t.start()
-
复制代码 今天可能在按下button 1 失败然后就报错关闭了
但有时在任务管理器背景还是存在WebChrome
|
|