16 July 2024 Leave a comment QA
When working with Selenium WebDriver for automated testing, you might encounter Chrome’s “Do you want Google Chrome to save your password for this site?” pop-up. This can interrupt your test execution and lead to inconsistent results. This article will guide you through the steps to disable this pop-up using Java.
Method to Disable Password Save Pop-up
To disable the password save pop-up in Chrome, you need to set specific user preferences in ChromeOptions. Below is a step-by-step guide on how to achieve this:
Step-by-Step Instructions
- Import the required packages:
import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.HashMap; import java.util.Map;
- Create an instance of ChromeOptions and disable the password manager:
ChromeOptions options = new ChromeOptions(); options.addArguments("--start-maximized"); options.addArguments("--disable-web-security"); options.addArguments("--no-proxy-server"); Map prefs = new HashMap(); prefs.put("credentials_enable_service", false); prefs.put("profile.password_manager_enabled", false); options.setExperimentalOption("prefs", prefs);
- Initialize the ChromeDriver with the configured options:
ChromeDriver driver = new ChromeDriver(options);
Complete Code Example
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.util.HashMap;
import java.util.Map;
public class DisablePasswordSavePopup {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--disable-web-security");
options.addArguments("--no-proxy-server");
Map prefs = new HashMap();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
ChromeDriver driver = new ChromeDriver(options);
driver.get("https://yourwebsite.com");
// Your test code here
driver.quit();
}
}
Additional Considerations
While the above method effectively disables the password save pop-up, it’s crucial to keep your WebDriver and browser versions up to date to ensure compatibility. For more detailed guidance, refer to our documentation.
Enhancing Your Test Automation with Repeato
For those looking to streamline their testing further, consider using Repeato, a no-code test automation tool for iOS and Android. Repeato leverages computer vision and AI to create, run, and maintain automated tests quickly and efficiently. This tool is particularly beneficial for quality assurance teams, as it simplifies the setup and use of automated tests.
To learn more about how Repeato can enhance your testing processes, visit our about page or check out our comprehensive getting started guide.