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_(:з」∠)_
Related
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!
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
I am using:
chromedriver=2.26.436362
Chrome Version 55.0.2883.87 m (64-bit)
.Net C# 4.6.1 / Visual Studio 2015 Community Edition
I am seeing the following exception during website testing (this is my log4net entry):
FATAL2017-01-09 05:03:10 – no such session
(Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 6.1.7601 SP1 x86_64)
FATAL2017-01-09 05:03:10 – at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScriptCommand(String script, String commandName, Object[] args)
at OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScript(String script, Object[] args)
I start my driver session like this:
var options = new ChromeOptions();
options.AddArguments("test-type");
options.AddArgument("incognito"); // works
options.AddArgument("--disable-bundled-ppapi-flash"); // works! this turns off shockwave
options.AddArgument("--disable-extensions"); // works
options.AddArguments("--start-fullscreen");
var driver = new ChromeDriver(options);
driver.Manage().Cookies.DeleteAllCookies();
return driver;
And I navigate to a "new" tab in Chrome with the following command:
lock (Session.Driver)
{
JavaScriptExecutor jscript = Session.Driver as IJavaScriptExecutor;
jscript.ExecuteScript(string.Format("window.open('{0}', '_blank');", url));
}
Which works in DEBUG 100% of the time. In RELEASE mode, I receive the error above. Which makes this a difficult problem to resolve...no debugger.
I have checked and the session is active, and at the point of entry two handles in Driver.WindowHandles corresponding to the tabs in Chrome are available. I have resorted to Console.Writeline() statements to view variables that I would normally diagnose in the watch window in visual studio debug mode.
I have been unable to reproduce this exception while debugging. It always "works" during debugging.
There are 5-10 other SO posts about the same issue. The answers to those questions involved updating the chromedriver.exe (I have the latest, and also tried older versions), or, are working with a different technology stack. There must be something else going on here.
Notes:
I can reproduce this error every time in RELEASE mode. However in DEBUG mode it works every time (no error).
I tried downgrading to chrome32_53.0.2785.116 (I uninstalled version 54) - same results no improvement.
I checked which chrome driver I'm using for DEBUG: it is exactly the same chromedriver.exe used during RELEASE. (this leads me to conclude that neither Chrome, nor the Chrome driver, are the culprit).
I discovered that I had to remove "optimize code" setting from Project->Properties->Build->(Release Configuration)->uncheck "optimize code".
I do not know why the "optimize code" setting would cause this issue.
I cannot claim credit. I followed the instructions at this SO post for the solution. See Josh Berke's post.
Found same error when running ChromeDriver in multithreading.
Try to add:
ChromeOptions chromeOptions = new ChromeOptions();
.....
chromeOptions.AddArgument("--disable-impl-side-painting"); //it worked for me
.....
var tmp = new ChromeDriver(service, chromeOptions);
I'm trying to get a few demo test to run using chrome, but i got the following error:
An exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll but was not handled in user code
Additional information: The HTTP request to the remote WebDriver server for URL http://localhost:57523/session timed out after 60 seconds.
I already added the chromedriver to the solution, first I hardcoded the path when declaring the driver, but then I found this post: Selenium WebDriver.ChromeDriver Nuget package installed, but not working for MSTest and followed some of the steps (from 2 to 4).
This is the code i'm using:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
namespace TestDemo1
{
[TestClass]
public class UnitTest1
{
static IWebDriver driver;
[AssemblyInitialize]
public static void SetUp(TestContext context)
{
//driver = new FirefoxDriver();
driver = new ChromeDriver();
}
[TestMethod]
public void TestMethod1()
{
driver.Navigate().GoToUrl("http://www.hazmeelchingadofavor.com");
}
[TestMethod]
public void TestMethod2()
{
driver.Navigate().GoToUrl("http://www.google.com");
driver.FindElement(By.Id("gbqfq")).SendKeys("Selenium");
driver.FindElement(By.Id("gbqfq")).SendKeys(Keys.Enter);
}
[AssemblyCleanup]
public static void TearDown()
{
driver.Quit();
}
}
}
I'm using VS Express 2013 for Web, in case you were wondering, also when I use the firefox driver, everything works perfectly
EDIT 10/23/2014:
Chrome Version: 38.0.2125.104 m
Chrome Driver: 2.11
Selenium .Net: 2.43.1
Windows: 7 Enterprise 64 bit
It is a known bug: https://code.google.com/p/chromedriver/issues/detail?id=928
try to update to Chrome Driver: 2.12, this version fix another issue:
Resolved issue 916: Selenium (javascript) fails when switching to webview window in Chrome apps [Pri-2] - https://code.google.com/p/chromedriver/issues/detail?id=916
may be it solves your problem. For me downgrading chrome and using old driver solved problem
Found the solution, we put a bit more attention into the error message and found a message about the sockets (can't recall it really good) so we call the IT department and ask for someone to come over, we talked the issue and the possible solution, so the solution:
Long Story Short:
The anti-virus was blocking the chromedriver so it couldn't connect, so the IT guy added a rule to allow full execution on chromedriver and that was it, hours and hours of research and the issue was the anti-virus, if you have a similar problem check with your IT department