How to disable dns over https in selenium - selenium

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);

Related

How to enable save passwords using selenium chromedriver

when I start chromedriver by default password save options are disabled (I can see options to save password are enabled in chrome config), but when I log in any website, chromedriver never ask me to save the password.
For my tests I need to save passwords, I have tried some options but nothing works.
I used same profile to open chromedriver, so I don't use the temporary profiles that chromedriver creates every time I launch it.
(sorry about my english)
Selenium Java
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", true);
prefs.put("profile.password_manager_enabled", true);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
driver = new ChromeDriver(options);
Selenium Python
var options = new ChromeOptions();
options.AddUserProfilePreference("credentials_enable_service", true);
options.AddUserProfilePreference("profile.password_manager_enabled", true);
var driver = new ChromeDriver(options);

Chrome options Proxy Bypass List not working

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");

How to handle or supress warning in Katalon for Chrome browser "This type of file can harm you computer. Do you want to keep it anyway?"

I want to suppress the above alert mentioned in the title while running my Katalon scripts.
Attaching screenshots for same:
It possible we have to run the chromedriver in safe mode.please try the below code
System.setProperty("webdriver.chrome.driver", "C:/chromedriver/chromedriver.exe");
String downloadFilepath = "D:/MyDeskDownload";
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
chromePrefs.put("safebrowsing.enabled", "true");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(cap);
You can set up the browser to automatically download files. The following is taken from Katalon forum:
First you add Chrome preferences:
HashMap<String, Object> chromePrefs = new HashMap<String, Object>()
chromePrefs.put("download.default_directory", downloadPath)
chromePrefs.put("download.prompt_for_download", false)
And then specify the path to ChromeDriver and add experimental options:
System.setProperty("webdriver.chrome.driver", "DriverFactory.getChromeDriverPath()")
ChromeOptions options = new ChromeOptions()
options.setExperimentalOption("prefs", chromePrefs)
NOTE:
You will need to import the following (or press CTRL+SHIFT+O for automatic imports):
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import com.kms.katalon.core.webui.driver.DriverFactory

How to add allow site on location of chrome content setting with selenium

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);

Selenium:Google Chrome Options and capabilities

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