Handling HTTP Proxy Authentication Pop-ups
HTTP Proxy Authentication pop-ups appear when accessing sites that require credentials at the proxy/server level before the page loads.
Method 1 — Embed credentials in URL (simplest):
// Format: http://UserName:Password@Example.com
driver.get("http://admin:admin@the-internet.herokuapp.com/basic_auth");
// Real example
driver.get("https://admin:admin@the-internet.herokuapp.com/basic_auth");
Method 2 — WebDriverWait + Alert.authenticateUsing():
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
alert.authenticateUsing(new UserAndPassword("username", "password"));
Method 3 — Firefox Profile pre-configured:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.http.phishy-userpass-length", 255);
FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);
WebDriver driver = new FirefoxDriver(options);
Method 4 — Chrome extension approach:
// Programmatically create a Chrome extension that handles auth
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("proxy_auth_extension.crx"));
WebDriver driver = new ChromeDriver(options);
Method 5 — DevTools Protocol (Chrome):
ChromeDriver chromeDriver = (ChromeDriver) driver;
Map<String, Object> headers = new HashMap<>();
headers.put("Authorization", "Basic " + Base64.getEncoder().encodeToString("user:pass".getBytes()));
chromeDriver.executeCdpCommand("Network.setExtraHTTPHeaders",
Collections.singletonMap("headers", headers));
URL credential format:
http://UserName:Password@Example.com
https://admin:secretpass@internal.company.com/app
Key point: Form authentication URL by embedding username and password directly in the URL. Example:
- ✓
http://the-internet.herokuapp.com/basic_auth(no credentials — prompts popup) - ✓
https://admin:admin@the-internet.herokuapp.com/basic_auth(bypasses popup)
