【问题标题】:Cannot start the driver service on http://localhost无法在 http://localhost 上启动驱动程序服务
【发布时间】:2019-02-21 04:54:48
【问题描述】:
如果我在没有接口的 Windows 服务器上运行 selenium,我想寻求帮助,我收到以下错误:
无法在http://localhost:49906/ 上启动驱动程序服务
OpenQA.Selenium.DriverService.Start() 在
OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(命令
commandToExecute) 在
OpenQA.Selenium.Remote.RemoteWebDriver.Execute(字符串
driverCommandToExecute,Dictionary`2 参数)在
OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities
所需能力)在
OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor
commandExecutor,ICapabilities 期望能力)在
OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService 服务,
ChromeOptions 选项,TimeSpan 命令超时)在
OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions 选项)
【问题讨论】:
标签:
c#
.net
selenium
selenium-chromedriver
windows-server
【解决方案1】:
将我的目标框架更改为 .NET Core 2.1(之前设置为 .NET Core 3.0)
现在它的工作。
【解决方案2】:
在我的情况下,这是因为有太多的后台 chrome 进程正在运行。以管理员身份运行 cmd 并使用 taskkill /f /im chromedriver.exe 杀死所有 chrome 驱动程序实例并使用 taskkill /f /im chrome.ext /t 杀死所有 chrome 实例使其工作。
【解决方案3】:
使用 Selenium 打开的浏览器需要在 Session 0(Windows 中的 GUI 界面)中运行。您提供的错误最有可能是对此问题的引用。
您可以尝试在无头模式下运行浏览器来解决 Session 0 问题,因为它不需要在 UI 中呈现。
怎么做你可以通过这个链接查看Headless Chrome
【解决方案4】:
正如我写的here:
当服务启动时,唯一执行的事情是带有驱动程序服务的进程和对该服务的 api 调用。
可能出现的问题可能是:
- 您无法执行该进程,因为无法访问可执行文件
- 某些配置阻止您成功执行 api 调用并到达http://localhost:60623/
- 代理设置(添加
NO_PROXY 环境变量,不包括 localhost 可能会有所帮助)
- 防火墙设置
- 端口已使用
【解决方案5】:
正在运行 VPN 客户端?为了完全隔离(对于业余爱好者),不能直接访问作为 Ip 和/或主机名的环回(除非客户端提供排除 localhost 或 127.0.0.1(及其 Ipv6 等效项)的可能性 - 曾经吓坏我当我仅仅因为我的 Cyberghost 客户端还在运行而无法让驱动程序工作时就像疯了一样,但回到最可能的原因:
尤其是在大量使用端口时,可能还有大量驱动程序,手动管理端口或至少手动检查/设置驱动程序服务的端口会有所帮助。
我这样做:我得到所有当前活动的 TcpConnections(本地端点)。我从给定范围内为驱动程序服务创建一个随机端口,直到分配的端口当前未被使用。
var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
var tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
do
{
driverService.Port = Random.Next(29999,65535);
} while (tcpConnInfoArray.Any(d => d.LocalEndPoint.Port == driverService.Port));