首先定位到 Python 安装目录下的services.py文件,路径格式如下:
Python安装路径\Lib\site-packages\selenium\webdriver\common\services.py
修改 start () 方法的,新增 creationflags 参数
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, stdin=PIPE, creationflags=134217728, ) except TypeError: raise
修改后保存文件,重新用 Pyinstaller 打包脚本,运行 exe 文件即可看到 driver 控制台黑框消失