您看到的错误是:
WebDriverException: Message: connection refused
根据文档WebDriverException
, 基本的webdriver异常 如下:
exception selenium.common.exceptions.WebDriverException(msg=None, screen=None, stacktrace=None)
因此
connection is refused here意味着
Selenium无法通过以下方式建立您想要建立的连接:
self.driver = webdriver.Firefox(profile, log_path = logfile)
一种可能的解决办法是提供的完整名称
logfile与沿
logical location的
logfile(从
Project Level)如下:
self.driver = webdriver.Firefox(firefox_profile=profile, log_path='./Log/geckodriver.log')
在这里您可以找到类似的
Discussion
再次,正如您提到的
When I used a time.sleep(10) just before the webdriver.Firefox line,the error did not show up anymore,因此我假设以前有个实例
GeckoDriver和一个
Firefox Browser客户端处于活动状态。因此,与@Florent B.提到的类似,您必须屏蔽脚本以防止遇到“
竞跑条件” ,而后者可能源于以下任一情况:
- 通过新会话访问相同的 日志文件 ,而先前的会话尚未释放。
- 通过新会话访问新的会话,或者通过新会话访问相同的 端口号 ,而先前的会话尚未释放。
GeckoDriver
Marionette
- 缺少访问 CPU* 的权限 *
- 缺乏 物理记忆
- 交换内存* 不足 *
- 光盘缓存* 不足 *
- 缺乏 网络带宽
Docker Image
跑 出来的内存
在这里您可以找到类似的
Discussion。
根据上述原因,您需要执行以下几个步骤:
- 总是使用最新发布的版本
Selenium-Python
的客户端,WebDriver variant
(GeckoDriver
)和Web Browser
(Firefox Browser
) - 始终使用 退出() 的
tearDown()
方法,以便webdriver
与webclient
两者都正确销毁。 Clean
该 项目工作 从你IDE
之前和执行你的后Test Suite
。Clear
执行之前和之后的 浏览器缓存Tests
CCleaner
定期使用工具抹去 OS琐事, 包括陈旧的东西rust_mozprofile directories
。



