I just wanted to know is it possible to set homepage of Chrome using capabilities and Chrome options in Selenium.
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);
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
Related
I am writing test using selenium, java, chrome.
How can I turn off "dns over https" in chrome settings?
I need it because my intranet DNS have different data than internet ones.
I've tried to add following options.
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("ignore-certificate-errors");
options.addArguments("--disable-async-dns");
options.addArguments("--dns-prefetch-disable");
options.addArguments("--disable-web-security");
ChromeDriver driver = new ChromeDriver(options);
It didn't help.
I've even tried to change options by clicking in settings
driver.get("chrome://settings/security");
String disableDNSOverHttpsButton = "/html/body/settings-ui//div[2]/settings-main//settings-basic-page//div[1]/settings-section[4]/settings-privacy-page//settings-animated-pages/settings-subpage/settings-security-page//settings-secure-dns//settings-toggle-button//div/cr-toggle";
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(disableDNSOverHttpsButton)));
driver.findElement(By.xpath(disableDNSOverHttpsButton)).click();
There is response "org.openqa.selenium.NoSuchElementException: "
local_state = {
"dns_over_https.mode": "off",
"dns_over_https.templates": "",
}
options.add_experimental_option("localState", local_state)
The solution is to use setExperimentalOption.
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
Map<String, Object> localState = new HashMap<String, Object>();
localState.put("dns_over_https.mode", "off");
localState.put("dns_over_https.templates", "");
options.setExperimentalOption("localState", localState) ;
ChromeDriver driver = new ChromeDriver(options);
I've been trying to add arguments to my Chrome Options to use a proxy and to ignore certain URL's.
I've followed the documentation and am trying to run this very simple test:
#Test
public void myTest(){
ChromeOptions options = new ChromeOptions();
options.addArguments("--proxy-server=http://XXX.XX.XX.XX:8080");
options.addArguments("--proxy-bypass-list=http://www.google.com");
System.setProperty("webdriver.chrome.driver", "C:/drivers/chromeDriver/win/chromedriver.exe");
ChromeDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com");
}
}
I've also tried with the variation:
options.addArguments("--proxy-bypass-list=*");
But it won't open the URL, is there something I'm doing wrong?
I guess you should use chromedriver.exe instead of eclipse.exe while setting property and make sure you have compatible chromedriver as per current version available in your system.
Here we go :
ChromeOptions options = new ChromeOptions();
options.addArguments("--proxy-server=http://XXX.XX.XX.XX:8080");
options.addArguments("--proxy-bypass-list=https://www.google.com");
System.setProperty("webdriver.chrome.driver", "driver_location\\chromedriver.exe");
ChromeDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com");
I am able to place extension using crx file. However, I need to change some setting in Chrome extension using selenium. Is there any chrome API or somehow I can automate this part. Appreciate!
When you instantiate the ChromeDriver, try using the below code:
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
I want to add site "a.com" on mobile chrome using selenium.
Option - [Advanced-content setting-location-ask before accessing-allow site]
Because i want to rid of the popup on my testing
Does anyone know?
To disable chrome asking for location you need to use ChromeOptions and disable geolocation from profile settings
ChromeOptions options = new ChromeOptions();
JSONObject jsonObject = new JSONObject();
jsonObject.put("profile.default_content_settings.geolocation", 2);
options.setExperimentalOption("prefs", jsonObject);
WebDriver driver = new ChromeDriver(options);
Please see that the whole answer is already explained in this SO post.
Edit : In case, the option is to be kept enabled, you just need to change this line
jsonObject.put("profile.default_content_settings.geolocation", 2);
to
jsonObject.put("profile.default_content_settings.geolocation", 1);
Use chrome devtools protocol can do this.Browser.grantPermission allow to config the geolocation permission before accessing the target website. You can look at my another answer for more detail Setting sensors (location) in headless Chrome
.
The below code snippet working for me to disable that pop up. Instead of profile.default_content_settings.geolocation,
I used profile.default_content_setting_values.notifications.
ChromeOptions options = new ChromeOptions();
JSONObject jsonObject = new JSONObject();
jsonObject.put("profile.default_content_setting_values.notifications", 1);
options.setExperimentalOption("prefs", jsonObject);
WebDriver driver = new ChromeDriver(options);
or
DesiredCapabilities caps = new DesiredCapabilities();
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
prefs.put("profile.default_content_setting_values.notifications", 1);
options.setExperimentalOption("prefs", prefs);
caps.setCapability(ChromeOptions.CAPABILITY, options);
Given the following code snippet:
case "CHROME":
System.setProperty("webdriver.chrome.driver", DriverPaths.CHROMEPATH);
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
options.addArguments("--disable-notifications");
options.addArguments("--start-maximized");
options.addArguments("--disable-web-security");
options.addArguments("--no-proxy-server");
options.addArguments("--enable-automation");
options.addArguments("--disable-save-password-bubble");
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
return new ChromeDriver();
Why am I still seeing:
And:
Any ideas?
You will have to use the following commands:
options is your chrome options.
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
By passing the capabilities to the chrome driver they will be loaded into chrome.
The DesiredCapabilities.chrome(); will select the correct browser, in this case Chrome.
Chrome asks for the password when your account is set for autologin.
Doing this makes it so that the keyring doesn't load when you
reset/reboot your system.
Chrome is asking for the password to the keyring so it can access
stored information in the keyring. You can view the keyring on your
system by running the command seahorse from a terminal window. You can
also just bypass the asking by closing the window and still get to
your sites without a problem. Some of the security may not load
properly.
However, you can use the following command from a terminal window to
bypass the keyring asking:
google-chrome-stable --password-store=basic
Hope this helps!
YOU CAN SET IT FOR YOUR CHROME LAUNCHER TOO
Courtesy of #Terrance