I created a very simple C# project to test Selenium and Chrome Driver, but when I run it, it gets stuck at the very first line, ie. creating ChromeDriver object.
I have set up as following:
.NET Core 3.1 console app (also tried .NET 4.7)
Installed Selenium.WebDriver 3.141.0 and Selenium.WebDriver.ChromeDriver 87.0.4280.8800.
My Chrome version is "Version 87.0.4280.88 (Official Build) (64-bit)". I have double-checked compatibility with Chrome and ChromeDriver.
Code:
using OpenQA.Selenium.Chrome;
namespace MyFirstSelenium
{
class Program
{
static void Main(string[] args)
{
ChromeDriver chrome = new ChromeDriver();
chrome.Navigate().GoToUrl("https://www.google.co.jp/");
}
}
}
visual studio screen
chromedriver.exe is copied to the debug folder as expected, so I assume the problem is neither compatibility nor path.
chromedriver
When I run the code, the result is an empty window with 'data' in the address bar. No error is thrown. I have searched for several hours and found some articles, but most of them are old and none of these answers led to success.
Any help is appreciated. Thank you.
Added chromedriver.exe verbose console output.
#Piotr M.
chromedriver console
logfile
https://drive.google.com/file/d/1ECOS8E55aaTFV63e8P-7n6uRVcf49PRN/view?usp=sharing
New code
Works when I first execute "chromedriver.exe --verbose --log-path=chromedriver.log", but without it, it throws WebDriverException.
OpenQA.Selenium.WebDriverException: 'A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL localhost:9515/session. The status of the exception was UnknownError, and the message was: No connection could be made because the target machine actively refused it. No connection could be made because the target machine actively refused it.'
var chromeOptions = new ChromeOptions();
chromeOptions.BrowserVersion = "87";
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:9515"), chromeOptions);
Possibly a classic case of cyclic redundancy.
chrome is a reserved word, you may have to change the variable name to something else e.g. chromex. So your effective line of code will be:
ChromeDriver chromex = new ChromeDriver();
Additional Consideration
Consider the following aspects aswell:
Instead of using the ChromeDriver class use the IWebDriver interface.
IWebDriver driver = new ChromeDriver();
Instead of the partial url google.co.jp/ you need to pass the complete url through GoToUrl() as follows:
driver.Navigate().GoToUrl(#"https://www.google.co.jp/");
Related
For this same error there are many questions in Stackoverflow. But none of them solved my problem. So I have to post this again.
My Code:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--disable-gpu");
options.AddArguments("--disable-extensions");
options.AddArgument(#"user-data-dir=C:\Users\myname\AppData\Roaming\Chrome\Profile 6");
options.AddArgument("--profile-directory=Profile 6");
IWebDriver driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("https://google.com");
Initially I was getting an error " Unable to move cache folder, access denied."
then I have added the line options.AddArguments("--disable-gpu"); and the error is gone.
Now my Code is opening the browser with profile : "Profile 6". But after that its throwing the error
Error in the line : IWebDriver driver = new ChromeDriver(options);
"Exception thrown: 'OpenQA.Selenium.WebDriverException' in WebDriver.dll
An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll
invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
"
I have already read almost all topics related to this error. Few of them are :
How to open a Chrome Profile through --user-data-dir argument of Selenium
InvalidArgumentException: Message: invalid argument: user data directory is already in use error using --user-data-dir to start Chrome using Selenium
How to initiate a new Chrome session when the default session is already running using ChromeDriver and Chrome through Selenium and Python
I am stuck in this problem for more than a week now. Please help.
EDIT:
To confirm that I am not using the already opened default user profile, I checked Cheome://version to confirm the user data directory path. Its different than the default.
Also I tried to to run the code after closing all the open chrome instances. This Time I have not received the error. The browser opened by the webdriver. But after that nothing happened. The code got time out error after 60 seconds in the line : IWebDriver driver = new ChromeDriver(options);
Possibly you are specifying the wrong directory. Instead of:
C:\Users\myname\AppData\Roaming\Chrome\Profile 6
You need to pass:
C:\Users\myname\AppData\Local\Chrome\Profile 6
So the effective line of code will be:
options.AddArgument(#"user-data-dir=C:\Users\myname\AppData\Local\Chrome\Profile 6");
Update 1
Additionally, you can remove the argument --profile-directory as in:
options.AddArgument("--profile-directory=Profile 6");
Update 2
If I close all the chrome instances and run the code, I am not getting this error means ChromeDriver is able to open the Chrome browsing instance perfectly. But to analyze why nothing happened can be interpreted from the TRACE level logs.
Ensure that:
JDK is upgraded to current levels JDK 8u251.
Selenium is upgraded to current levels Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v83.0 level.
Chrome is updated to current Chrome Version 83.0 level. (as per ChromeDriver v83.0 release notes)
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
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 and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
I have updated the latest selenium webdriver (v 3.4.0) installed and have latest firefox driver(0.15.0). I have these installed in a project which I am working on by "Manage Nuget Packages" option. Suddenly all of my tests are failing as it is not able to interact with any of the elements on firefox browser. To state about my issue, when I try the below simple tests on a google website
IWebDriver driver = new FirefoxDriver();
driver.Url = "https://www.google.com/";
var MyKeyWord = driver.FindElement(By.Id("lst-ib"));
MyKeyWord.SendKeys("Gmail");
it is failing with below exception.
An unhandled exception of type 'System.InvalidOperationException' occurred in WebDriver.dll
Additional information: Expected [object Undefined] undefined to be a string (IndexOutOfBounds)
I was searching on how to handle this problem and I found a solution as below:
driver = new FirefoxDriver(DRIVER_PATH);
But all my tests were executing without specifying these path in firefox earlier as firefox picks them when we install the required package using "Manage Nuget Packages" option. I am not sure why it started failing all of a sudden. Does someone have any suggestion on this?
Download latest geckodriver from https://github.com/mozilla/geckodriver/releases. Unzip it and put gecodriver file your system path. Restart (if needed) .
This link will help for setup : https://github.com/mozilla/geckodriver
I hope it will help.
There are two Chromedriver displays in NuGet manager - one driver for Chrome and other one is Selenium Google Chrome driver. You have to install both, then it works.
I have a super simple test script (below) to get started with WebDriver. When I run the test (C# - Visual Studio 2015), it opens up a Firefox browser and then does nothing.
There are several posts out there that talk about the following issue, which I'm also getting:
OpenQA.Selenium.WebDriverException: Failed to start up socket within 45000 milliseconds. Attempted to connect to the following addresses: 127.0.0.1:7055.
But those posts regarding this problem are quite old and also have one major difference- their FF browser didn't open; mine does.
The error:
The code:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace seleniumDemo
{
[TestClass]
public class UnitTest1
{
static IWebDriver driverFF;
[AssemblyInitialize]
public static void SetUp(TestContext context)
{
driverFF = new FirefoxDriver();
}
[TestMethod]
public void TestFirefoxDriver()
{
driverFF.Navigate().GoToUrl("http://www.google.com");
driverFF.FindElement(By.Id("lst-ib")).SendKeys("Selenium");
driverFF.FindElement(By.Id("lst-ib")).SendKeys(Keys.Enter);
}
}
}
This question is different from what's been suggested as a duplicate because the FireFox browser actually opens in this case. In the other questions, it wasn't responding at all.
it seems to be related to Selenium and Firefox version incompatibility. I also faced the same error when selenium on my machine was unable to communicate to firefox. I upgraded firefox to 46.x and it started working.
You can find version compatibility information over web or refer selenium changelog as well.
Use MarrioneteDriver to use latest version of Firefox.
Below is the Java code, you can write in C# accordigly (Make sure you have geckodriver.exe under BrowserDriver folder in your project folder)
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"/BrowserDrivers/geckodriver.exe");
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability("marionette", true);
WebDriver driver = new MarionetteDriver(cap);
You can download latest version of MarrioneteDriver from below :
https://github.com/mozilla/geckodriver/releases
And you should Marionette executable to Windows system path :
To add the Marionette executable to Windows system path you need
update the Path system variable and add the full directory to the
executable.
To do this, right-click on the Start menu and select System. On the
left-side panel click Advanced system settings and then Environment
Variables button from System Properties window. Now the only step left
to do is to edit Path system variable and add the full directory to
your geckodriver (you may need to add a semi-colon before doing this,
if not already present) and you’re good to go.
Then simply create your driver instance :
var driver = new FirefoxDriver(new FirefoxOptions());
I have an infuriating Selenium error:
The path to the driver executable must be set by the webdriver.chrome.driver system property
Here is the code I am using:
Environment.SetEnvironmentVariable("webdriver.chrome.driver", #"C:\ChromeDriver\chromedriver.exe");
DesiredCapabilities capability = DesiredCapabilities.Chrome();
ChromeOptions options = new ChromeOptions();
options.BinaryLocation = #"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
capability.SetCapability(ChromeOptions.Capability, options);
Uri url = new Uri("http://localhost:5050/wd/hub");
//error on this line
IWebDriver driver = new RemoteWebDriver(url, capability);
I have the driver on disk, at the location.
The selenium server is running, as shown below:
Server
I have added the selenium binary as a system variable, as shown below:
Variables
I have restarted the server too.
What am I missing? It feels as though I am doing everything correctly, but it's not working.
Thanks
With the new selenium, which is 3.0 you should use:
java -Dwebdriver.chrome.driver=path_to_chrome_driver -jar selenium-server-standalone-3.0.0-beta2.jar
If you are using selenium version below 3.0 you need to reverse the order of selenium with the driver, like:
java -Dwebdriver.chrome.driver=path_to_chrome_driver -jar selenium_server.jar
Also make sure selenium server is compatible with chromedriver.
Other thing to check is that chrome browser is up to date.
With latest Selenium WebDriver v 2.50.00 I am getting (again) following exception:
Failed to start up socket within 45000 ms. Attempted to connect to the
following addresses: 127.0.0.1:7055
executing:
driver = new FirefoxDriver(new FirefoxBinary(), firefoxProfile, pageLoadTimeout);
This happens with version 43 and higher of Firefox. I have downgraded Firefox to v. 39 and there it works OK.
It seems that this issue happened before couple of times with various versions of Selenium and Firefox, see here or here.
Any workaround for this or downgrading Firefox and waiting for a new version of Selenium WebDriver is the only way?
Yes, It is bug which still going to resolve for latest versions
You need set the Preferences as xpinstall.signatures.required", false.
Below code is working for me but it is in java. you get the idea where you need to change
WebDriver driver = null;
final FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("xpinstall.signatures.required", false);
driver = new FirefoxDriver(firefoxProfile);
driver.manage().window().maximize();
driver.get("https://www.google.co.in/");
Hope it will help you :)