I am trying to launch Chrome with a specific Homepage set. Given below is the code, I am using:
package WebDriverInitialization;
import java.util.HashMap;
import java.util.Map;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class LaunchChrome {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","D:\\Technology Lab\\+ProgramFiles\\selenium-drivers\\chromedriver.exe");
Map<String, Object> hmPrefs = new HashMap<String, Object>();
hmPrefs.put( "browser.startup.page", 1);
hmPrefs.put( "browser.startup.homepage", "http://www.seleniumhq.org");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("prefs", hmPrefs);
DesiredCapabilities chromeCaps = DesiredCapabilities.chrome();
chromeCaps.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver chromeDriver = new ChromeDriver(chromeCaps);
chromeDriver.manage().window().maximize();
}
}
When I run this, I get a blank page with 'data:,' in the URL - like how Chrome launches by default. Last line of the code is getting executed and the page is maximized.
I am using Selenium version 3.0.1
; java version 1.8.0_92
; Chrome version 56.0.2924.87
and ChromeDriver version 2.27.440174
on Windows 7 Professional SP1 x64
.
Can anyone point out the mistake in above code and get it to launch Chrome with http://www.seleniumhq.org
as the homepage?
Thanks!