---Advertisement---

How to Handle Proxy Authentication in Selenium WebDriver (Chrome) Using AutoIT and Alerts Great 2025

By Manisha

Updated On:

---Advertisement---
How to Handle Proxy Authentication in Selenium

📌How to Handle Proxy Authentication in Selenium WebDriver

Handle Proxy Authentication: A proxy server acts as a gateway between a client and the internet. It helps:

  • Improve privacy
  • Provide security
  • Enable content filtering (e.g., in schools or companies)

In web automation, proxies are often used when your application needs to run behind secure networks or restricted environments. Sometimes, these proxies require username and password authentication, which leads to a popup window — something that Selenium alone cannot handle.


📌 Difference Between SOCKS and HTTP Proxy

FeatureSOCKS ProxyHTTP Proxy
Full FormSecure SocketsHypertext Transfer Protocol Proxy
LayerTransport LayerApplication Layer
Use CaseAll protocols (TCP/UDP)Only HTTP/HTTPS
Data HandlingDoesn’t interpret trafficInterprets HTTP data
PerformanceSlightly slowerBetter performance
Best ForComplex traffic filteringWeb automation and scraping

📌 How to Handle Proxy Authentication in Selenium (Chrome Browser)

Handle Proxy Authentication: Selenium cannot handle OS-level authentication dialogs (like HTTP proxy popups) directly. There are three ways to bypass this limitation:

  1. Passing credentials in the URL (e.g., http://username:password@website.com)
  2. Using AutoIT
  3. Using Alert Popups in Selenium

We will focus on the second and third options, which are more reliable.


📌 Method 1: Using AutoIT to Handle Proxy Popups

Handle Proxy Authentication: Selenium WebDriver can only automate web-based popups, not OS-level popups. AutoIT is a Windows-based automation tool designed to handle these limitations.


📌 Steps to Handle Proxy Using AutoIT

  1. Install AutoIT on your Windows machine
  2. Open SciTE Script Editor
  3. Paste the script below and save it as ProxyAuthentication.au3
  4. Compile the file into an .exe using the AutoIT compiler

autoit

WinWaitActive(“Authentication Required”)

Send(“your-username”)

Send(“{TAB}”)

Send(“your-password”)

Send(“{ENTER}”)


📌 Selenium Integration Code (Java):

java

import java.io.IOException;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class HandleProxyWithAutoIT {

    public static void main(String[] args) throws IOException {

        System.setProperty(“webdriver.chrome.driver”, “path/to/chromedriver”);

        // Trigger AutoIT script

        Runtime.getRuntime().exec(“path/to/ProxyAuthentication.exe”);

        WebDriver driver = new ChromeDriver();

        driver.get(“http://your-proxy-protected-url.com”);

        // Your test logic

        driver.quit();

    }

}

AutoIT handles the popup silently. Selenium continues the test once authentication is complete.


📌 Method 2: Using Alerts in Selenium WebDriver

If the proxy authentication appears as a browser alert (rare, but possible), Selenium can handle it using its Alert interface.


  • Launch the Chrome browser
  • Open a URL that triggers a basic authentication popup
  • Enter credentials using sendKeys() on the alert popup

java

import org.openqa.selenium.Alert;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class ProxyAuthUsingAlert {

    public static void main(String[] args) {

        System.setProperty(“webdriver.chrome.driver”, “path/to/chromedriver”);

        WebDriver driver = new ChromeDriver();

        driver.get(“http://your-proxy-protected-url.com”);

        // Handle username alert

        Alert alert = driver.switchTo().alert();

        alert.sendKeys(“your-username”);

        alert.accept();

        // Handle password alert

        Alert alert2 = driver.switchTo().alert();

        alert2.sendKeys(“your-password”);

        alert2.accept();

        // Continue test

        driver.quit();

    }

}

Proxy popup is handled directly within Selenium using alerts. Authentication completes successfully.


📌 Summary: Best Way to Handle Proxy Authentication in Selenium

MethodUse CaseReliability
URL with credentialsOnly works if the browser allows this method⚠️ Low
AutoIT ToolOS-level popup handling✅ High
Alert HandlingOnly works for browser-based alerts✅ Medium

📌 Final Thoughts

  • Use AutoIT for handling proxy authentication popups on Windows
  • Use Selenium Alert interface if the popup appears as a browser alert
  • Avoid embedding credentials in the URL as it’s insecure and not browser-compatible anymore

✅ Pro Tip: Always test your authentication logic in different environments (Dev, QA, Prod) to make sure the proxy behaves consistently.

Testing Selenium Download

Right Click and Double

Leave a Comment

Index