【发布时间】:2019-01-14 04:14: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 应用程序时,我得到了这个:
似乎 Selenium 无法启动应用程序。 查看我得到的异常:
找不到 Chrome 二进制文件
很遗憾,我在网上没有找到类似的东西,有人可以帮助我吗?
提前致谢。
更新
我刚刚在我的 linux 机器上重新安装了Chrome,现在上面的错误消失了,但现在还有另一个问题,事实上我得到了这个错误:
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)
【问题讨论】:
-
使用基于 text 的错误跟踪日志更新问题
-
@DebanjanB 我添加了它
标签: c# google-chrome selenium selenium-webdriver selenium-chromedriver