python selenium 打包EXE後不開啟driver的控制檯!
阿新 • • 發佈:2021-02-10
用selenium寫了個自動IE11的測試程式,啟動時都會跳出個driver的控制檯,搜了些解決方案,有效的分享下。
開啟python安裝庫中selenium的程式檔案 Lib\site-packages\selenium\webdriver\common\service.py
找到start()函式
// An highlighted block
def start(self):
"""
Starts the Service.
:Exceptions:
- WebDriverException : Raised either when it can't start the service
or when it can't connect to the service
"""
try:
cmd = [self.path]
cmd.extend(self.command_line_args())
self.process = subprocess.Popen(cmd, env=self.env,
close_fds= platform.system() != 'Windows',
stdout=self.log_file, stderr=self.log_file, creationflags=CREATE_NO_WINDOW)
在引數stderr=self.log_file後新增creationflags=CREATE_NO_WINDOW
然後在service.py開頭匯入CREATE_NO_WINDOW 如下
from win32process import CREATE_NO_WINDOW
解決!PYTHON 3.7