Below is the selenium script to open chrome browser in C# on Windows 10 Visual Studio Code. I'm using Chrome 74 (64 bit) and corresponding ChromeDriver 74.0.3729.6. One thing to note is Chrome is not installed in default directory. This is due to our Office security purpose. It has installed in a different location. When I run the script It gives me error -Failed to create a Chrome process. Could some one please help me to understand why chrome browser isn't opening?
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using NUnit.Framework;
using SeleniumExtras.PageObjects;
namespace NAS
{
[TestFixture]
class Program
{
public static IWebDriver driver;
public Program(){}
[OneTimeSetUp]
public void startBrowser()
{
ChromeOptions opt = new ChromeOptions();
opt.BinaryLocation = @"C:\\ProgramData\\Microsoft\\AppV\\Client\\Integration\\520B8677-106E-430B-8927-6F9261C56329\\Root\\VFS\\ProgramFilesX86\\Google\\Chrome\\Application\\";
driver = new ChromeDriver(@"C:\\Progra~1\\Selenium",opt);
driver.Navigate().GoToUrl("http://www.google.com");
driver.Manage().Window.Maximize();
}
[Test]
public void testLogin()
{
Console.WriteLine("test running..");
}
[OneTimeTearDown]
public void closeBrowser()
{
driver.Close();
}
}
}
Error:
Running selected tests in c:\NAS\bin\Debug\netcoreapp2.2\NAS.dll
NUnit3TestExecutor converted 1 of 1 NUnit test cases
TearDown failed for test fixture NAS.Program
**OpenQA.Selenium.WebDriverException : unknown error: Failed to create a Chrome process.**
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.14393 x86_64)
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
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 NAS.Program.startBrowser() in c:\NAS\Program.cs:line 30
--TearDown
at NAS.Program.closeBrowser() in c:\NAS\Program.cs:line 46
NUnit Adapter 3.12.0.0: Test execution complete
NAS.Program.testLogin: failed
Total tests: 1. Passed: 0. Failed: 1. Skipped: 0
After adding executable name - chrome.exe
Running selected tests in c:\NAS\bin\Debug\netcoreapp2.2\NAS.dll
NUnit3TestExecutor converted 1 of 1 NUnit test cases
SetUp failed for test fixture NAS.Program
OpenQA.Selenium.WebDriverException : unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\ProgramData\Microsoft\AppV\Client\Integration\520B8677-106E-430B-8927-6F9261C56329\Root\VFS\ProgramFilesX86\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.14393 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 NAS.Program.startBrowser() in c:\NAS\Program.cs:line 28
NUnit Adapter 3.12.0.0: Test execution complete
NAS.Program.testLogin: failed
Total tests: 1. Passed: 0. Failed: 1. Skipped: 0