OpenQA.Selenium.WebDriverException:未知错误:Chrome无法启动:在Linux上通过Selenium start执行测试时异常退出 [英] OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally while executing tests through Selenium start on linux
问题描述
我使用.NetCore创建了一个使用 Selenium 的应用程序,以便在Linux上使用它,实际上这是我的代码实现:
I created an application that use Selenium using .NetCore for use it on Linux, actually this is my code implementation:
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作为驱动程序,我下载了它在这里,我还将驱动程序添加到了程序集的文件夹中,这样ChromeDriver便知道了在哪里进行搜索.
as you can see I am using as driver Chrome, I downloaded it here, I also added the driver inside the folder of the assembly, in this way the ChromeDriver knows already where to search it.
在linux上,我使用 chmod -R 777 更改了文件夹权限,但是当我运行Dotnet应用程序时,我得到了以下提示:
On linux I changed the folder permission using chmod -R 777, but when I run my Dotnet application I get this:
似乎 Selenium 无法启动该应用程序. 查看异常,我得到:
Seems that Selenium cannot start the application. Looking at the Exception I get:
找不到Chrome二进制文件
Cannot find Chrome binary
不幸的是,我没有在网络上找到任何类似的东西,有人可以帮助我吗?
Unfortunately I didn't find anything similar on the web, someone could help me?
谢谢.
更新
我刚刚在Linux机器上重新安装了Chrome
,现在上面的错误消失了,但是现在还有另一个问题,实际上我得到了这个错误:
I Just reinstalled Chrome
on my linux machine and now the error above went away, but there is another problem now, infact I get this error:
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
...表示 ChromeDriver 无法启动/产生新的 WebBrowser ,即 Chrome浏览器会话.
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
您的主要问题是所使用的二进制文件版本之间的不兼容性:
Your main issue is the incompatibility between the version of the binaries you are using as follows:
- 您使用的是 chromedriver = 2.9 ,它非常古老.
- You are using chromedriver=2.9 which is pretty ancient.
因此 ChromeDriver 版本( v2.33 )与最新的 Chrome浏览器版本( vVersion 68.0 )
So there is a clear mismatch between the ChromeDriver version (v2.33) and the recent Chrome Browser version (vVersion 68.0)
- 将 ChromeDriver 升级到当前的 ChromeDriver v2.41 级别.
- 将 Chrome 版本保持在 Chrome v67-69 级别之间. (根据ChromeDriver v2.41发行说明) 通过 IDE
- 清理您的项目工作区和重建您的项目,并且仅具有必需的依赖项.
- 如果您的基本 Web客户端版本太旧,请通过来卸载. Revo Uninstaller 并安装最新版本的 Web客户端 GA和发行版.
- 执行您的
@Test
.
- Upgrade ChromeDriver to current ChromeDriver v2.41 level.
- Keep Chrome version between Chrome v67-69 levels. (as per ChromeDriver v2.41 release notes)
- Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
- If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
- Execute your
@Test
.
您可以在以下位置找到一些相关的讨论:
You can find a couple of relevant discussions in:
- WebDriverException:消息:未知错误:Chrome无法启动:在debian服务器上使用ChromeDriver Chrome和Selenium异常退出了
- 消息:未知错误:Chrome无法启动:在具有Linux 4.9.85-38.58.amzn1.x86_64 x86_64 的AWS Cloud9上异常退出
- WebDriverException:消息:未知错误:Chrome无法启动:ChromeDriver在VPS上通过Python异常退出了ChromeDriver Chrome和Selenium
- WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium on debian server
- Message: unknown error: Chrome failed to start: exited abnormally on AWS Cloud9 with Linux 4.9.85-38.58.amzn1.x86_64 x86_64
- WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium through Python on VPS
这篇关于OpenQA.Selenium.WebDriverException:未知错误:Chrome无法启动:在Linux上通过Selenium start执行测试时异常退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!