Greetings StackOverflow Community,
My issue is simple. I have the following five lines of code, that I can't figure out why Google Chrome doesn't launch google.com when using a custom binary location.
var Chrome = new ChromeOptions();
Chrome.AddArgument("no-sandbox");
Chrome.BinaryLocation = #"C:\GoogleChrome\chrome.exe";
ChromeDriver driver = new ChromeDriver(#"C:\ChromeDriver", Chrome);
driver.Navigate().GoToUrl("https://www.google.com");
Any ideas? All I get is the default chromedriver URL of "data:," when Google Chrome launches.
Why isn't the driver.navigate command working when using a Chrome.BinaryLocation? If I comment out that line, than it works fine.
I am using the following:
Windows 7
Visual Studio Community Edition 2017
Google Chrome version 67
chromedriver 2.41
.NET 4.5 Bindings
hey i dont think you need of binary location
And maybe Chrome is already a type,
try this:
ChromeOptions options = new ChromeOptions();
options.AddArgument("no-sandbox");
var driver = new ChromeDriver(#"C:\GoogleChrome", options);
driver.Navigate().GoToUrl("https://www.google.com");
Okay, I found the answer to this question. I don't know why the Portable version of either Firefox, Chrome or other Chromium based browsers do not function this way, but I resolved this issue by copying the enterprise installation files from program files for Chrome to another directory on the computer and then pointing the Selenium script to use that binary location. Then it worked just fine.
It was also useful to point Chrome to a custom chrome profile location to keep more of the Chrome application from using the local users's AppData folder.
If anyone is interested in accomplishing the same task, I can provide some example code that accomplishes this task. Just message me for more details.
Related
Is it possible to open my own (normal) chrome browser and have selenium run on this browser?
I saw some existing topics about this wrt. Python: Running Selenium on an existing Chrome Browser Window, how is someone doing this through C# and Selenium?
Type : chrome://version/ in browser you will get executable path of chrome.exe
copy this and close all chrome instance.
**close all chrome instance and **
start chrome as:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --remote-debugging-port=5555
verify chrome is started with port open by going to localhost:5555
Now add remote debugging port as:
var options = new ChromeOptions();
options.debuggerAddress= "127.0.0.1:5555";
var driver = new ChromeDriver(options);
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.
unexpectedly I am experiencing this issue. I am trying to run my testcase. For Firefox or IE browser but I don't know where is the issue. It cannot find the browser location.
Selenium.WebDriver -Version 2.52.0
Selenium.Support -Version 2.52.0
Selenium.RC -Version 2.52.0
Selenium.WebDriverBackedSelenium -Version 2.52.0
It was working perfectly but soon after I updated my nupackages. I am having this issue. Also I tried to use previous version but now I am having same problem in that one as well.
Error:
IEDriver
FirefoxDriver Error
Enviorment Variable
Installed Location:
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
C:\Program Files\Mozilla Firefox\firefox.exe
Make sure you're mentioning path of IEDriverServer executable in PATH variable of your system.
echo $PATH
https://github.com/SeleniumHQ/selenium/wiki/FirefoxDriver
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
It happened to me as well. I tried to download older version from the below link and it worked. Let me know, if that helped. About IE I am trying to figure it out what should be the case.
Firefox version download
You don't need to alter your code. Also Anderson is right you probably might have downloaded x64 version and I think Selenium might be trying to find x86 version (in Program File) which might have caused the problem.
For IE Driver download it (32bit) LINK
After that your browser init need to be something like that:
InternetExplorerDriverService driverService = InternetExplorerDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
driverService.LibraryExtractionPath = #"c:\drivers\"; // here is your driver location
InternetExplorerOptions options = new InternetExplorerOptions();
options.EnableNativeEvents = true;
options.IgnoreZoomLevel = true;
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
driver = new InternetExplorerDriver(driverService, options, TimeSpan.FromSeconds(180));
For Firefox just try to update the firefox to last version.
Using Selenium Grid2 and RemoteWebDriver in an MSTest class, I am struggling to get OperaDriver working.
I create the Selenium hub and Opera node by running the following commands in CMD:
start java -jar selenium-server-standalone-2.30.0.jar -role hub
start java -jar selenium-server-standalone-2.30.0.jar -role node -port 7001 -browser "browserName=opera,version=11.62,maxInstances=5,platform=WINDOWS" -hub http://localhost:4444/grid/register
And this works fine, I can the see the registered node when I view my hub in a browser.
But I get an exception whenever I try to create a new WebDriver in my C# test class:
DesiredCapabilities operaCapabilities = DesiredCapabilities.Opera();
operaCapabilities.SetCapability(CapabilityType.BrowserName, "opera");
operaCapabilities.SetCapability(CapabilityType.Platform, "WINDOWS");
operaCapabilities.SetCapability(CapabilityType.Version, "11.62");
operaCapabilities.SetCapability("opera.binary", "C:\\Program Files\\Opera\\opera.exe");
operaCapabilities.SetCapability("opera.port", 7001);
RemoteWebDriver operaDriver = new RemoteWebDriver(operaCapabilities);
Actually I get two different exceptions - the first time after creating the hub and node in Selenium I get this:
Could not find a platform that supports bundled launchers, please set
it manually
Build info: version: '2.30.0', revision: 'dc1ef9c', time: '2013-02-19
00:15:27'
System info: os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2',
java.version: '1.7.0_15'
Driver info: driver.version: OperaDriver
And everytime after that I get the following error:
Could not initialize class
com.opera.core.systems.runner.launcher.OperaLauncherRunner
I am using Selenium-standalone-2.30.0.
I was using Opera version 12.14 but downgraded to 11.62 after I saw a list of compatible versions on the OperaDriver wiki page but the errors remain the same.
I have tried initialising the RemoteWebDriver with and without the capabilities above and get the same result every time.
Does anyone know what the problem is here and how to get a RemoteWebDriver working with Opera in this way?
Edit: Could it be that the platform for Opera version 12.14 reads as 'WINDOWS 8', and version 11.62 reads as "WIN32" when I open the Opera browser and view Help => About? As I am specifying the platform as WINDOWS in the node and RemoteWebDriver. If I try to specify WINDOWS 8 as the platform for the RemoteWebDriver an new exception is thrown where it can't find matching enum:
org.openqa.selenium.WebDriverException:
java.lang.IllegalArgumentException: No enum constant
org.openqa.selenium.Platform.WINDOWS 8
Edit2: For some reason CurrentPlatform is returning Vista for me, even though I am running Windows8.
Platform platform = Platform.CurrentPlatform;
And I also noticed that the OperaDriver source code checks for 'VISTA' in uppercase whereas the Platform in C# reads as 'Vista'.
Could this be causing the problem?
I've been suffering from this problem as well and thanks to the hint from eviltester I was able to solve the issue by using the following command line to start the selenium server:
java -Dos.name=windows -jar selenium-server-standalone-2.32.0.jar
The use of -Dos.name=windows is the equivalent of System.setProperty("os.name", "windows") and will allow your C# selenium code to work for the Opera browser.
I saw this when running in Java. In debug mode it looked like a possible omission in OperaLauncherRunner.java launcherNameForOS does not cater for the WIN8 enum returned by Platform.getCurrent().
In Java I fudged it by setting the system property "os.name" to "windows" before creating a new OperaDriver. This forced the Platform.getCurrent to return XP which the opera launcher was happy with.
So in java I just used this hack:
System.setProperty("os.name","windows");
driver = new OperaDriver();