Selenium dotnet 的 Chrome 进程不会在生产中启动

问题描述 投票:0回答:1

我在 asp.net web api 中使用 Selenium webdriver,此代码在本地工作,但在生产中部署时,它表示 chrome 进程无法启动。 Webdriver.exe部署在wwwroot下,与Chrome版本相同。这是代码

ChromeOptions options = new ChromeOptions();
           
options.AddArgument("--no-sandbox");
options.AddArgument("--headless");
options.AddArgument("--ignore-ssl-errors=true");
options.AddArgument("--ignore-certificate-errors");
options.AddArgument("--window-size=1920x1080");
options.AddArgument("--disable-gpu");
options.AddUserProfilePreference("download.default_directory", "Downloads");
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("safebrowsing.enabled", false);
 
string chromeDriverPath = @"C:\Users\Gentrit\source\repos\Azon\Azon\bin\Debug\net8.0";

using (var driver = new ChromeDriver(_hostingEnvironment.WebRootPath, options)){
    // The error is thrown here, cant create chrome process
}

我已经对代码进行了所有更改,selenium 已更新,我制作了 chrome.exe 的副本并将其发布在 wwwroot 中,并将其路径引用为二进制位置,似乎没有任何效果 这是完整的错误

[Error] Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer: Connection ID "18014398527467168636", Request ID "4000237f-0004-fa00-b63f-84710c7967bb": An unhandled exception was thrown by the application.
OpenQA.Selenium.WebDriverException: unknown error: Failed to create Chrome process.at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)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 OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)at Azon.Controllers.HomeController.UploadImageAsync(IFormFile image) in C:\Users\Gentrit\source\repos\Azon\Azon\Controllers\HomeController.cs:line 100at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)at Program.<>c.<<<Main>$>b__0_10>d.MoveNext() in C:\Users\Gentrit\source\repos\Azon\Azon\Program.cs:line 151--- End of stack trace from previous location ---at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()
c# asp.net .net selenium-webdriver webdriver
1个回答
0
投票

通过在 azure 中创建虚拟机并安装所有所需的依赖项,问题已得到解决。

© www.soinside.com 2019 - 2024. All rights reserved.