I just wanted to know is it possible to set homepage of Chrome using capabilities and Chrome options in Selenium.
2 Answers
Yes it is possible to instantiate ChromeDriver
with using both DesiredCapabilities
and ChromeOption
to set your desired Homepage as below :-
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
Map<String, Object> preferences = new HashMap<String, Object>();
preferences.put( "browser.startup.homepage", "http://my.home.page" );
preferences.put( "browser.startup.page", START_WITH_HOME_PAGE );
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", preferences);
capabilities.setCapability( ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
-
It does not answer the question. You're not setting the homepage in chrome using capability and chrome options like was asked. You are using capabilities and options, and then only navigating to the desired page using
driver.get()
Commented Aug 9, 2016 at 19:18 -
@ParkerBeck ah, thanks to point it out, actually I didn't understand the question, now updated with correction.....:) Commented Aug 9, 2016 at 19:38
-
1Hi Saurabh Gaur,please correct me, I am not able to get START_WITH_HOME_PAGE . Do we need to pass URL here? I am geeting error that START_WITH_HOME_PAGE can't be resolved to a variable Commented Aug 10, 2016 at 6:16
Just to be clear, the capabilities you are trying to set here are options that you use to customize and configure a ChromeDriver session. Below are the keys which you can use to set for that session:
"browser.startup.homepage", "startup.homepage_welcome_url", "startup.homepage_welcome_url.additional"
etc.
You can pass URL for these or if you don't want you can also set something like : "about:blank"
as value