问题描述:
Python+selenium程序经过pyinstaller打包成exe文件后,启动exe文件后,会打开一个XXXdriver.exe的cmd窗口,直接关闭cmd窗口会导致程序打开的浏览器被关闭。
目的:
保持浏览器打开,并且关闭cmd窗口。
解决方法:
1.修改service.py文件
文件位置:
......Python\Python38\Lib\site-packages\selenium\webdriver\common\service.py
修改内容
1.引入库
import sys
2.start函数替换(实际上只修改了try块中的内容)
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.e