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:
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!
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!
Related
I'm using C# and Selenium and Chromedriver to run tests.
I'm getting this error:
Unhandled exception. OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /Applications/Google Chrome.app/Contents/MacOS/Google Chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
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(ChromeOptions options)
But it only crashes if I remove the _chromeOptions.AddArgument("headless");, and only on a Mac. I tested on an Intel Mac, an M1 Mac, and a Windows. Windows runs without headed just fine.
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
ChromeOptions _chromeOptions = new ChromeOptions();
_chromeOptions.AddArgument("headless");
_chromeOptions.AddArgument("version");
IWebDriver Driver = new ChromeDriver(_chromeOptions);
Driver.Navigate().GoToUrl("https://google.com");
Driver.Close();
From existing SO posts and other resources I found, I have tried adding various other arguments to chromeoptions including:
--headless=false
--no-sandbox
--disable-gpu
--verbose
and also specifying the binary:
_chromeOptions.BinaryLocation = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome";
I'm using an M1 Macbook Pro, Visual Studio for Mac 17.4.3 (build 21), Selenium.Webdriver 4.8.0, Selenium.Webdriver.ChromeDriver 109.0.5414.7400, and Google Chrome 109.0.5414.87 (Official Build) (arm64)
Because the driver is initialized deep in an in-house library, I can't simply remove the version line, and I need it to not be headless so I can verify the test I'm writing actually does what it's supposed to.
I'm new to C# and trying to follow a webscrape tutorial.
Currently i have these software installed:
Visual Studio 2022
.NET.Core 6.0
Selenium.WebDriver(from negut for project?)
Chrome ver.101.0.4951.64
ChromeDriver ver.101.0.4951.41 newest one i can found
Codes are here:
namespace WebScrape
{
class Program
{
static void Main(string[] args)
{
IWebDriver drive = new ChromeDriver();
drive.Navigate().GoToUrl("www.google.com");
}
}
}
After running the code, chrome do open, but only a blank page shown up with url "data:;"
the console shows:
Starting ChromeDriver 101.0.4951.41 (93c720db8323b3ec10d056025ab95c23a31997c9-refs/branch-heads/4951#{#904}) on port 12473
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
DevTools listening on ws://127.0.0.1:12476/devtools/browser/cfbbc4af-00d4-45c6-87a0-11cc31baa733
Unhandled exception. OpenQA.Selenium.WebDriverArgumentException: invalid argument
(Session info: chrome=101.0.4951.64)
at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.WebDriver.set_Url(String value)
at OpenQA.Selenium.Navigator.GoToUrl(String url)
at WebScrape.Program.Main(String[] args) in D:\DEV\CSharp_PROJ\WebScrape\WebScrape\Program.cs:line 17
[8060:25652:0512/142113.378:ERROR:device_event_log_impl.cc(214)] [14:21:13.378] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: 连到系统上的设备没有发挥作用。 (0x1F)
Possible solution i have tried:
Try different chromedirver version.(failed)
Download older chrome version to match chromedriver version exactly.(failed)
Please, can I get some help_(:з」∠)_
Information
Hello mates! Several days ago, I've ran into issue with Selenium and that is to be exact the error in the title. I have been trying to resolve this issue myself for some days now with no luck at all. Chrome is being run from external file, when I try to open manually, it works. If I try to run the driver from the default location, it works. I've tried different versions of Selenium with no luck and different versions of Chrome.
Expected results
ChromeDriver will execute chrome.exe.
Actual results
ChromeDriver fails to start chrome.exe for unknown reason.
CLI Picture
Code
ChromeDriver driver = new ChromeDriver(new ChromeOptions { BinaryLocation = Path.Combine(Environment.CurrentDirectory, #"GoogleChromePortable") });
Exception details
OpenQA.Selenium.WebDriverException
HResult=0x80131500
Message=unknown error: Failed to create Chrome process.
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 Self_Contained.Program.Main(String[] args) in *:\*\*\SFC\Program.cs:line 11
After hours of research I found somewhere that excluding chrome.exe may lead to this issue. I added chrome.exe to the binary path and voilà it is working.
Ever since the latest Chromium update I have been unable to run Selenium on Linux (.NET Core)
Google Chrome is installed on usr/bin/google-chrome, and I have made sure of it as I have ran it directly from the directory it's stored in.
Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729#{#29}) on port 32911
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Unhandled Exception: OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome 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=Linux 4.15.0-45-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 selenium.Program.Main() in REDACTED
Aborted (core dumped)
I have tried disabling shm, use headless mode, and other recent issues on this topic, but none have worked.
ChromeOptions options = new ChromeOptions();
options.AddArguments("--headless --no-sandbox");
options.AddUserProfilePreference("profile.default_content_setting_values.images", 2);
IWebDriver webDriver = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory, options);
webDriver.Navigate().GoToUrl(#"file:///login.html");
The expected output is for ChromeDriver not to throw an exception and crash.
I created an application that use Selenium using .NetCore for use it on Linux, actually this is my code implementation:
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));
}
}
as you can see I am using as driver Chrome, I downloaded it here, I also added the driver inside the folder of the assembly, in this way the ChromeDriver knows already where to search it.
On linux I changed the folder permission using chmod -R 777, but when I run my Dotnet application I get this:
Seems that Selenium cannot start the application.
Looking at the Exception I get:
Cannot find Chrome binary
Unfortunately I didn't find anything similar on the web, someone could help me?
Thanks in advance.
UPDATE
I Just reinstalled Chrome on my linux machine and now the error above went away, but there is another problem now, infact I get this error:
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)
This error message...
OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.9 which is pretty ancient.
So there is a clear mismatch between the ChromeDriver version (v2.33) and the recent Chrome Browser version (vVersion 68.0)
Solution
Upgrade ChromeDriver to current ChromeDriver v2.41 level.
Keep Chrome version between Chrome v67-69 levels. (as per ChromeDriver v2.41 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Execute your #Test.
References
You can find a couple of relevant discussions in:
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium on debian server
Message: unknown error: Chrome failed to start: exited abnormally on AWS Cloud9 with Linux 4.9.85-38.58.amzn1.x86_64 x86_64
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium through Python on VPS
first, check your google-chrome version
then download related chromedriver version i.e