Ripper
Ripper

Reputation: 127

C# Selenium ChromeDriver Invalid --log-level value. Unable to initialize logging

The following code is not working:

ChromeOptions op = new ChromeOptions {
    BinaryLocation = "./chromedriver.exe"
};
op.AddArguments("--disable-logging", "--headless", "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage");
ChromeDriver driver = new ChromeDriver(op);

Error:

OpenQA.Selenium.WebDriverException HResult=0x80131500 Message=unknown error: Chrome failed to start: was killed. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location ./chromedriver.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.) Source=WebDriver StackTrace: 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(ChromeOptions options) at WebScraper.Utility.GetChromeBrowser(String binaryLocation) in C:\Users\AB\Documents\Code\CSharp\WebScraper\WebScraper\WebScraper\Utility.cs:line 20 at WebScraper.Program.d__0.MoveNext() in C:\Users\AB\Documents\Code\CSharp\WebScraper\WebScraper\WebScraper\Systems\Program.cs:line 7

Last Console Output:

Invalid --log-level value. Unable to initialize logging. Exiting...

I have tried other answers on the web and have been stuck on this problem for two days now. The arguments I have added, excluding the --headless, are arguments I have tried to get the WebDriver to start working, to no avail. Below is the directory the .exe file is within: enter image description here

I have tried disabling logging using the arguments, but it still did not work. It says it needs a "DevToolsActivePort" file, but I'm not sure how to get that file or where to put it. Is it possible to have a separate browser for my selenium application rather than using a browser already installed on a computer? Have the application self-contained rather then depending on external installations? Any suggestions will be extremely helpful!

Upvotes: 2

Views: 1135

Answers (1)

Ripper
Ripper

Reputation: 127

I figured it out. I needed two .exe files, one being the Chrome driver and the other being the Chrome browser.

Install Chrome, then go to the path it was installed in (usually "C:\Program Files\Google"), copy the entire "Chrome" folder and paste it into the application directory. This is the Chrome browser.

Then, make the BinaryLocation of ChromeOptions the path to the "chrome.exe" inside of the "Chrome" folder you pasted. Mine was: "./Chrome/Application/chrome.exe" Now, "BinaryLocation" is pointing to the browser.

Then, create a ChromeDriverService using the ChromeDriverService.CreateDefaultService static method. Point it to the folder that contains the "chromedriver.exe," the driver. It must point to the driver, not the browser.

Feed the ChromeOptions and ChromeDriverService into the ChromeDriver constructor, and you are all set!

Upvotes: 5

Related Questions