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.
Related
I'm facing some issues while handling "Untrusted Certificate" in firefox.
We can't use FirefoxDriver(new FirefoxProfile) as it is deprecated
I used the following code but couldn't achieve it.
FirefoxProfile profile=new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
FirefoxOptions options=new FirefoxOptions().setProfile(new FirefoxProfile());
WebDriver driver=new FirefoxDriver(options);
driver.get("Web Link");
Could anyone suggest me the solution to achieve in Selenium 3.
Try this in Firefox
DesiredCapabilities handlSSLErr = DesiredCapabilities.firefox ();
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new FirefoxDriver (handlSSLErr);
driver.get("Your URL link");
For chrome
DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome ();
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new ChromeDriver (handlSSLErr);
driver.get("Your URL link");
Below works fine for me
DesiredCapabilities cap = new DesiredCapabilities().merge(DesiredCapabilities.firefox());
cap.acceptInsecureCerts();
FirefoxDriver driverF = new FirefoxDriver(cap);
driverF.get("https://expired.badssl.com/");
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.
Written below code for chrome to disable web security
System.setProperty("webdriver.chrome.driver", "D:\\Eclipse\\chromedriver_win32\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
/*options.addArguments("test-type");
options.addArgument("--start-maximized");*/
options.addArguments("--disable-web-security");
/* options.addArguments("--allow-running-insecure-content");*/
capabilities.setCapability("chrome.binary","D:/Eclipse/chromedriver_win32/chromedriver.exe");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(options);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(options);
But I want to disable same for FF and IE.
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);
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());