遇到错误不要慌,先仔细看看报什么错
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Microsoft Edge failed to start: exited normally.
(session not created: DevToolsActivePort file doesn't exist)
(The process started from msedge location C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe is no longer running, so msedgedriver is assuming that msedge has crashed.)
原来是好的,自从在程序里用–user-data-dir指定了用户数据文件夹后就报错了
检查了浏览器版本以及驱动版本没有问题。
结合日志,不难看出是因为浏览器启动时没有创建这个DevToolsActivePort这个端口的session会话导致,那为啥没启动呢?
因为不是selenium启动的浏览器呗
解决方法:
打开任务管理器,干掉所有正在运行的浏览器进程,然后再启动你的selenium程序就好了
如果不想干掉现有的,那就不要指定–user-data-dir或者再复制一份user data文件夹也可以,参考上一篇文章
selenium非全新的方式同时启动多个浏览器又互不影响的一种实现方法,欢迎讨论!