OpenQA.Selenium.WebDriverException:未知错误:Chrome 无法启动:在 Linux 上通过 Selenium start 执行测试时异常退出

2023-11-29

我创建了一个使用的应用程序Selenium使用 .NetCore 在 Linux 上使用。这是我的代码实现:

public class Program 
{
    public static async Task Main(string[] args)
    {
        //Settings for chrome
        var chromeOpts = new ChromeOptions();
        chromeOpts.AddArgument("headless");
        chromeOpts.AddArgument("no-sandbox");

        //Get assembly path where chrome driver is located
        string codeBase = Assembly.GetExecutingAssembly().CodeBase;
        UriBuilder uri = new UriBuilder(codeBase);
        string path = Uri.UnescapeDataString(uri.Path);
        path = Path.GetDirectoryName(path);

        var driver = new ChromeDriver(path, chromeOpts, TimeSpan.FromSeconds(180));
    }
}

如您所见,我使用 Chrome 作为驱动程序。我下载了here。我还在程序集的文件夹中添加了驱动程序。通过这种方式,ChromeDriver 已经知道在哪里可以找到它。

在 Linux 上我使用更改了文件夹权限chmod -R 777但是,当我运行 Dotnet 应用程序时,我得到以下信息:

enter image description here

看来Selenium无法启动应用程序。 看看我得到的异常:

找不到 Chrome 二进制文件

不幸的是我在网上没有找到类似的东西。

UPDATE

我重新安装了Chrome在我的 Linux 机器上,现在上面的错误消失了,但现在还有另一个问题。我收到此错误:

OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally  (Driver info: chromedriver=2.9.248304,platform=Linux 4.4.0-130-generic x86_64)   
  at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)   
  at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)   
  at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)   
  at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)   
  at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)   
  at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options, TimeSpan commandTimeout)\   at ODS.Program.Main(String[] args)

这个错误信息...

OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally

...意味着Chrome驱动程序无法启动/产生新的网页浏览器 i.e. Chrome浏览器会议。

你的主要问题是不兼容您正在使用的二进制版本之间的关系如下:

  • 您正在使用chromedriver=2.9这是相当古老的。

所以两者之间存在明显的不匹配Chrome驱动程序版本 (v2.33)以及最近的Chrome浏览器版本 (版本 68.0)

Solution

  • Upgrade Chrome驱动程序至当前Chrome驱动程序v2.41 level.
  • Keep Chrome版本之间铬 v67-69水平。 (根据 ChromeDriver v2.41 发行说明)
  • Clean your 项目工作区通过你的IDE and Rebuild您的项目仅具有所需的依赖项。
  • 如果你的基地网页客户端版本太旧,然后通过卸载雷沃卸载程序并安装最新的 GA 和发布版本网页客户端.
  • 执行你的@Test.

参考

您可以在以下位置找到一些相关讨论:

  • WebDriverException:消息:未知错误:Chrome 无法启动:debian 服务器上的 ChromeDriver Chrome 和 Selenium 异常退出
  • 消息:未知错误:Chrome 无法启动:在使用 Linux 4.9.85-38.58.amzn1.x86_64 x86_64 的 AWS Cloud9 上异常退出
  • WebDriverException:消息:未知错误:Chrome 无法启动:在 VPS 上通过 Python 使用 ChromeDriver Chrome 和 Selenium 异常退出
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

OpenQA.Selenium.WebDriverException:未知错误:Chrome 无法启动:在 Linux 上通过 Selenium start 执行测试时异常退出 的相关文章

随机推荐