99from selenium .webdriver .support .ui import WebDriverWait
1010from selenium .webdriver .support import expected_conditions as EC
1111
12+ from src .utils .const import Key , AppPath
1213from src .utils .log import Log
1314from src .core .clock import clock
1415from src .core .login import login
1516from src .core .captcha import captcha , Selectors
17+ from src .utils .utils import Utils
18+
1619
1720@dataclass
1821class Config :
@@ -25,6 +28,7 @@ class Config:
2528 wait_time : int = 2
2629 always_retry : bool = False
2730 show_web_page : bool = True
31+ auto_update_driver : bool = True
2832
2933class AutoClock :
3034 def __init__ (self , config : Config ):
@@ -37,12 +41,35 @@ def __init__(self, config: Config):
3741 self .remote_url = config .remote_url
3842 self .always_retry = config .always_retry
3943 self .show_web_page = config .show_web_page
44+ self .auto_update_driver = config .auto_update_driver
4045 self .driver = None
4146 try :
4247 self .driver = self .create_driver ()
4348 except Exception as e :
4449 Log .error (f"Create driver error: { e } " )
45- raise Exception (f"Failed to create WebDriver: { e } " )
50+
51+ if 'version' in str (e ):
52+ try :
53+ if not self .auto_update_driver :
54+ raise Exception ("Edge version not support, need to redownload driver." )
55+
56+ ok , driver_path = Utils .download_edge_web_driver ()
57+ if not ok :
58+ raise Exception ("Redownload Edge web driver error." )
59+
60+ self .driver_path = driver_path
61+ self .driver = self .create_driver ()
62+
63+ if self .driver is not None :
64+ data = Utils .read_dict_from_json (AppPath .DataJson )
65+ data [Key .DriverPath ] = self .driver_path
66+ Utils .write_dict_to_file (AppPath .DataJson , data )
67+
68+ except Exception as e :
69+ Log .error (f"Redownload and Create driver error: { e } " )
70+ raise Exception (f"Failed to create WebDriver: { e } " )
71+ else :
72+ raise Exception (f"Failed to create WebDriver: { e } " )
4673
4774 def create_driver (self ):
4875 # 创建浏览器驱动
0 commit comments