1

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!

Somnath Musib
  • 3,548
  • 3
  • 34
  • 47
John
  • 11
  • 1
  • 3
  • I don't see any calls to navigate to a particular page. Have you tried chromedriver.navigate.to()? – Special Character Feb 18 '17 at 03:04
  • 1
    My objective is to launch chrome with a specific homepage without needing to navigate to a url. – John Feb 18 '17 at 05:20
  • have you tried with `chromeCaps .setCapability("chrome.switches", Arrays.asList("--homepage=http://www.seleniumhq.org"));` – Akash KC Feb 20 '17 at 04:29
  • 1
    @LolCoder아카쉬 Thanks. This also doesn't seem to work. Launches chrome with 'data:,' in URL. – John Feb 20 '17 at 17:26

1 Answers1

0

Try this:

chromeOptions.setArguments("google-base-url=MY_URL");

From doc: Define kGoogleBaseURL

Specifies an alternate URL to use for speaking to Google. Useful for testing.