我想在 Linux ARM64 上使用 Chrome 运行 Selenium,使用 .net 6 程序 dockerized。
.csproject
<PackageReference Include="Selenium.WebDriver" Version="4.18.1" />
<PackageReference Include="WebDriverManager" Version="2.17.2" />
FooService.cs
new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser, Architecture.X64);
var cService = ChromeDriverService.CreateDefaultService();
_driver = new ChromeDriver(cService, options);
程序工作正常,直到触发 Selenium 部分。
System.Exception: Unable to locate installed browser for runtime platform Unix
at WebDriverManager.Helpers.RegistryHelper.GetInstalledBrowserVersionLinux(String[] executableAndArgumentsPairs)
at WebDriverManager.DriverConfigs.Impl.ChromeConfig.GetRawBrowserVersion()
at WebDriverManager.DriverConfigs.Impl.ChromeConfig.GetMatchingBrowserVersion()
at WebDriverManager.DriverManager.GetVersionToDownload(IDriverConfig config, String version)
at WebDriverManager.DriverManager.SetUpDriver(IDriverConfig config, String version, Architecture architecture)
at Blabla.Services.Foo.StartChrome() in /src/Bla/FooService.cs:line 46
我是手动安装在容器中的 chrome linux64 https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.94/linux64/chrome-linux64.zip
还尝试过 chrome mac-arm64 https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.94/mac-arm64/chrome-mac-arm64.zip
curl -L -o chrome-headless-shell.zip "https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.22/linux64/chrome-headless-shell-<file>.zip"
unzip chrome-headless-shell.zip -d /opt
rm chrome-headless-shell.zip
export PATH="/opt:${PATH}"
但错误仍然存在...
我使用 Java,但也在 Linux 上
我有以下完美运行的设置:
private void initChromeDriver() {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
}
....setting needed Chrome options if running on Chrome
而且,我的 WebDriverManager (bonigarcia) 是 5.1.1 WebDriver (selenium-api) - 4.1.2