Issue
im using Selenium webdriver in asp.net web api and this code works locally but in production when deployed it says chrome process wont start. Webdriver.exe is in wwwroot deployed, and it has the same version as Chrome. Here is the code
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
}
I've made all changes to the code, selenium is updated, ive made a copy of chrome.exe and published it in wwwroot and made a reference to its path as binary location, nothing seems to work Here is the full error
[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()
Solution
The problem has been solved by creating a virtual machine in azure and installing all the needed dependencies.
Answered By - Gentrit Cunaj
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.