How to enable save passwords using selenium chromedriver - selenium

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

Related

How to disable dns over https in 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);

Selenium newer Chrome cannot disable browser notification (Tried other solns)

I know this is an old question, and I've tried answers from a few posts such as Disable Chrome notifications (Selenium)
Unfortunately none worked, the browser notification popup still comes and interrupts my simulations.
My Chrome version is 75.0.3770.100 (Official Build) (64-bit), running on MacOS.
Edit:
After this question was marked as a duplicate of How to disable push-notifications using Selenium for Firefox and Chrome?, I've tried the solutions, but it still did not work for me.
String chromePath = "somepath/selenium-2.48.2/chromedriver";
System.setProperty("webdriver.chrome.driver", chromePath);
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.notifications", 2);
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
options.addArguments("--disable-notifications");
driver = new ChromeDriver(options);
Below are the original solutions I tried.
String chromePath = "somepathto/chromedriver";
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--disable-notifications");
System.setProperty("webdriver.chrome.driver", chromePath);
WebDriver driver = new ChromeDriver(chromeOptions);
// Login
try {
driver.get(sometestURL);
driver.manage().window().maximize();
// do some operations
} catch (Exception ex) {
System.out.println(ex);
}
I also tried this:
String chromePath = "somepath/selenium-2.48.2/chromedriver";
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.notifications", 2);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("prefs", prefs);
System.setProperty("webdriver.chrome.driver", chromePath);
WebDriver driver = new ChromeDriver(chromeOptions);
But the notification still comes "xxxxwebsite wants to show notifications Allow Block" on the upper left of the window.
What I did not do right?
I just tested this on Windows with Chrome 75.0.3770.142 (64 bit) and ChromeDriver 75.0.3770.90 (see log below) against web site https://www.nzz.ch (because it asks for permission to show push notifications). I used Selenium 3.14.0.
08:27:37.184 [main] INFO i.g.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as C:\Users\xxxxx\.m2\repository\webdriver\chromedriver\win32\75.0.3770.90\chromedriver.exe
Starting ChromeDriver 75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770#{#1003}) on port 32864
For me the switch also mentioned here and in the linked resources reliably deactivates the popup from being displayed:
options.addArguments("--disable-notifications");
Changing the default setting profile.default_content_setting_values.notifications is not necessary in my case. So if this does not work for you
either you are not setting the option correctly,
you are using a (possibly outdated) ChromeDriver version not supporting it or
for some reason on MacOS the driver does not implement it.
P.S.: In both Firefox and Chrome for me it was not problem to e.g. click links and navigate to other pages even during the notification pop-up was shown. Did you have any problems there or is the pop-up just an annoyance?

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

Unable to find element on new tab link

When I run a browser with extension a pop up arise that says "Disable developer mode" to do so my script clicks on Disable, it opens a new tab with url "chrome://extensions/"
Now to click on checkbox of developer mode it always give an error "Unable to locate element."
driver.findelement(By.id("toggle-dev-on"));
http://prntscr.com/f8fbde
Here is the solution for your Question:
As per best practices to work with Selenium 3.4.0 you must download the latest chromedriver v2.29 from here, update your Google Chrome to 58.x.
Updating your chromedriver to v2.29 will solve your issue of Disable developer mode
To work with Google Chrome you can take help of ChromeOptions Class as follows:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("https://gmail.com");
Let me know if this solves your Question.
You need to modify the appropriate browser profile to have JS disabled. Like for FireFox/Chrome you can tell Selenium which profile to use.
Chrome :
Map prefs = new HashMap();
prefs.put("profile.default_content_setting_values.notifications", 2);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
FireFox :
FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.setPreference("dom.webnotifications.enabled", false);
WebDriver driver = new FirefoxDriver(ffprofile);
Hope this will work out for your case.

Disable Google Chrome password bubble for WebDriver tests

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