Selenium Grid test Error - selenium

I have a hub with 2 nodes. My tests are not running with the error
Unable to cast object of type 'System.String' to type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]
This is my tests and my browser...
DesiredCapabilities capabilities = DesiredCapabilities.Chrome();
ChromeOptions options = new ChromeOptions();
options.AddArguments("test-type");
options.BinaryLocation = #"C:\Users\ebrahimpour.l\Documents\Visual Studio 2015\Projects\FirstPackage\FirstPackage\bin\Debug\chro‌​medriver.exe";
capabilities.SetCapability("chrome.binary", #"C:\Users\ebrahimpour.l\Documents\Visual Studio 2015\Projects\FirstPackage\FirstPackage\bin\Debug\chro‌​medriver.exe");
capabilities.SetCapability(ChromeOptions.Capability, options);
System.Environment.SetEnvironmentVariable("webdriver.chrome.‌​driver",
#"C:\Users\ebrahimpour.l\Documents\Visual Studio 2015\Projects\FirstPackage\FirstPackage\bin\Debug\chro‌​medriver.exe");
driver = new ChromeDriver(#"C:\Users\ebrahimpour.l\Documents\Visual Studio 2015\Projects\FirstPackage\FirstPackage\bin\Debug");
capabilities.SetCapability(capabilities.Platform.ProtocolPlatformType, "WebDriver");
capabilities.SetCapability(CapabilityType.BrowserName, "chrome");
capabilities.SetCapability(capabilities.Version, "57");
capabilities.SetCapability(CapabilityType.Platform, "WinNT");
capabilities.SetCapability(ChromeOptions.Capability, options);
RemoteWebDriver rw = new RemoteWebDriver(new Uri("http://localhost:4444/grid/console"), capabilities);
driver = rw;
baseURL = "http://192.168.10.173:8080/";
verificationErrors = new StringBuilder();

Change
RemoteWebDriver rw = new RemoteWebDriver(newUri("**http://localhost:4444/grid/console**"), capabilities);
to
http://localhost:**8888**/**wd/hub**

Related

HtmlUnit set download location

Currently I am executing selenium script with HtmlUnit. How can I set the Download location for the zip file downloaded at the time of test script execution.
You can use ChromeDriver in headless mode. You just need to add options as headless as below:
chromeOptions.addArguments("--headless");
The full code in Java will appear as below:
System.setProperty("webdriver.chrome.driver","D:\\Workspace\\JmeterWebdriverProject\\src\\lib\\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://google.com");
You can use ChromeDriver to set download in a specific path by below code:
String downloadFilepath = "/path/to/download";
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(cap);

Possible to add Chrome option and capabilities together?

Possible to add Chrome option and capabilities together?
In need to combine the following listed below together, is it even possible?
System.setProperty("webdriver.chrome.driver", Base_Page.getConstant(Constant.CHROME_DRIVER_DIRECTORY));
ChromeOptions options = new ChromeOptions();
string[] switches = {"user-data-dir=C:\\Users\\AppData\\Local\\Google\\Chrome\\User Data"};
options.addArguments("user-data-dir=C:\\Users\\AppData\\Local\\Google\\Chrome\\User Data");
options.addArguments("test-type");
options.addArguments("--start-maximized");
options.addArguments("--disable-extensions");
options.addArguments("no-sandbox");
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
options.(CapabilityType.LOGGING_PREFS, logPrefs);
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(caps);
DesiredCapabilities caps = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
caps.setCapability("chrome.switches", switches);
//webdriver = new ChromeDriver(caps);
webdriver = new ChromeDriver(options);
Searched the same question.
The answer is: just add all your Capabilities into the "options" object and launch browser using options:
ChromeOptions options = new ChromeOptions();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
webdriver = new ChromeDriver(options);
Updating to latest version of chrome driver fixed my issue:
ChromeDriver 2.28
if you observe ChromeDriver constructor in below link
http://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/chrome/ChromeDriver.html
It will accept capabilities or options, means any one. I hope it clears you.

Unable to add desired capabilities for remote web driver

I am unable to compile my code when I try to add the following to enable selenium node on my machine.
URL hubUrl = new URL("");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
capabilities.setPlatform(Platform.LINUX);
RemoteWebDriver driver = new RemoteWebDriver(hubUrl, capabilities);
probably you forgot to add the Hub url.
Try this:
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
or another variant:
URL hubUrl = new URL("http://hubIP:hubPort/wd/hub");
DesiredCapabilities capability = DesiredCapabilities.firefox();
capabilities.setPlatform(Platform.LINUX);
RemoteWebDriver driver = new RemoteWebDriver(hubUrl, capabilities);

What is the C# equivalent to Java ChromeOptions.setExperimentalOptions()?

I have automated android chrome browser with the below code:
DesiredCapabilities capabilities=DesiredCapabilities.chrome();
ChromeOptions options=new ChromeOptions();
options.setExperimentalOptions("androidPackage", "com.android.chrome");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver=new ChromeDriver(capabilities);
System.setProperty("webdriver.chrome.driver", "C://Users//Documents//Appium//ChromeDriver//chromedriver.exe");
String url="http://yahoo.com";
driver.get(url);
I am trying to automate android chrome browser using C# (Visual Studio) but can't find the equivalent code. I am using this but not working:
Capabilities = DesiredCapabilities.Chrome();
ChromeOptions options1=new ChromeOptions();
options1.AddAdditionalCapability("androidPackage", "com.android.chrome",);
Driver = new ChromeDriver(Chrome_Driver, options1);
I believe this is what you're looking for:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddAdditionalCapability("androidPackage", "com.android.chrome");
driver = new RemoteWebDriver(new Uri("http://seleniumhubaddress:4444/wd/hub"), chromeOptions.ToCapabilities());

RemoteWebDriver Chrome - start maximized

I need chrome to start maximized when running via the selenium grid.
This is how do I initialize it now:
Selenium selenium = new DefaultSelenium("localhost", 4444, "*googlechrome", "http://www.google.com");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Chrome does come up, but not maximized. In usual ChromeDriver I did it like this
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
But I dont know how to pass it to RemoteWebDriver. Can anybody help?
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
That's how I do it.
Ok, I found it, so lets answer my own question :)
Selenium selenium = new DefaultSelenium("localhost", 4444, "*googlechrome", "http://www.google.com");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
should work :}
The above solutions did not work for me but this did
ChromeOptions options = new ChromeOptions();
options.AddArguments("--start-maximized");
DesiredCapabilities capabilities = options.ToCapabilities() as DesiredCapabilities;
capabilities?.SetCapability(CapabilityType.BrowserName, "chrome");
Driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities);
Hope this helps someone.