Handling Login Popups in Selenium WebDriver and Java
Related Product On This Page What is an Authentication Pop-upJune 18, 2026 · 8 min read · Tool Comparison
Login popups are a common protection mechanism on modern websites, often need authentication through a username and password. However, deal these popups in Selenium can be challenging since the elements can not be now audit for locators. This guide explains different approaches to automatize login popups in Selenium WebDriver with Java, including passing certification in the URL, using the AutoIt tool, and leverage Chrome DevTools Protocols (CDP) in Selenium 4. When users admission any protected web URL, an authentication pop up is displayed to enter credentials. These type of popups commonly use Basic Authentication, which is a method for an HTTP exploiter agent (For example: a web browser) to provide a username and watchword when do a postulation. The client sends HTTP requests with the Authorization header that control the news Basic follow by a infinite and a base64-encoded twine username and password. Authorization header format Authorization: Basic & lt; base64 encoded certificate & gt; Credentials are a combination of username and password distinguish by a colon. admin: admin For example, to authorize asadmin: adminthe node would post the followers Authorization: Basic YWRtaW46YWRtaW4= When the host receives this request, it can access the Authorization header, decode the credential, and seem up the exploiter to determine if they should be allowed access to the quest resource. Now let us plunk into different manner to handle such login pop-ups. For a project, add the Selenium Java, WebDriverManager, and TestNG addiction in the pom.xml file. & lt; dependency & gt; & lt; dependency & gt; & lt; groupId & gt; org.seleniumhq.selenium & lt; /groupId & gt; & lt; artifactId & gt; selenium-java & lt; /artifactId & gt; & lt; version & gt; 3.141.59 & lt; /version & gt; & lt; /dependency & gt; & lt; dependance & gt; & lt; groupId & gt; io.github.bonigarcia & lt; /groupId & gt; & lt; artifactId & gt; webdrivermanager & lt; /artifactId & gt; & lt; version & gt; 5.2.1 & lt; /version & gt; & lt; /dependency & gt; & lt; dependency & gt; & lt; groupId & gt; org.testng & lt; /groupId & gt; & lt; artifactId & gt; testng & lt; /artifactId & gt; & lt; version & gt; 7.6.1 & lt; /version & gt; & lt; /dependency & gt; & lt; /dependencies & gt; Also Read: This is the simplest alternative by straight surpass username and parole in the URL severalize by colon. After “ https: // ” and before domain gens, pass credentials as & lt; username & gt;: & lt; password & gt; follow by “ @ ”. Syntax: https: // & lt; username & gt;: & lt; password & gt; @ & lt; domain & gt; Example:https: //admin: admin @ the-internet.herokuapp.com/basic_auth public class PassingInURL { WebDriver driver; String username; String password; String field; String url; @ BeforeTest public nothingness setUp () { WebDriverManager.edgedriver () .setup (); // Instantiate the webdriver driver = new EdgeDriver (); username = & # 8220; admin & # 8221;; password = & # 8220; admin & # 8221;; area = & # 8220; the-internet.herokuapp.com/basic_auth & # 8221;; } @Test public void launch () { url = & # 8220; https: // & # 8221; + username + & # 8220;: & # 8221; + password + & # 8220; @ & # 8221; + arena; driver.get (url); String text = driver.findElement (By.cssSelector (& # 8220; div.example p & # 8221;)) .getText () .trim (); Assert.assertEquals (text, & # 8220; Congratulations! You must have the proper credentials. & # 8221;); } @ AfterTest public nihility tearDown () { driver.quit (); } } Read More: Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script. AutoIt is a third-party tool that can be integrated with Selenium script to assist automate popups in Windows. Auto IT is freeware scripting language designed to automatize Windows GUI. It uses a combination of mouse movement, keystrokes, and window control manipulation to automatize a workflow in Windows which is not possible with Selenium. Example: Login.au3 Send (& # 8220; admin & # 8221;) Send (& # 8220; {TAB} & # 8221;) Send (& # 8220; admin & # 8221;) Send (& # 8220; {ENTER} & # 8221;) Runtime.getRuntime () .exec (& # 8220; D: \\Auto IT\\Login.exe & # 8221;); public class AutoIT { WebDriver driver; String url; @ BeforeTest public vacuum setUp () { WebDriverManager.chromedriver () .setup (); // Instantiate the webdriver driver = new ChromeDriver (); url = & # 8220; http: //the-internet.herokuapp.com/basic_auth & # 8221;; } @Test public void launching () throws InterruptedException, IOException { driver.get (url); driver.manage () .timeouts () .pageLoadTimeout (10, TimeUnit.SECONDS); Runtime.getRuntime () .exec (& # 8220; D: \\Auto IT\\Login.exe & # 8221;); Thread.sleep (2000); String schoolbook = driver.findElement (By.cssSelector (& # 8220; div.example p & # 8221;)) .getText () .trim (); Assert.assertEquals (text, & # 8220; Congratulations! You must receive the proper credentials. & # 8221;); } @ AfterTest public void tearDown () { driver.quit (); } } Selenium 4 has introduced a new API that grants access to Chrome DevTools straightaway from your automated examination. This is done via the Chrome DevTools protocol (CDP), which is fundamentally a set of tools that enables you to access and control Chromium-based browsers. Add below Selenium4 addiction instead of Selenium3 to pom.xml file and salve it: & lt; colony & gt; & lt; dependency & gt; & lt; groupId & gt; org.seleniumhq.selenium & lt; /groupId & gt; & lt; artifactId & gt; selenium-java & lt; /artifactId & gt; & lt; variant & gt; 4.0.0-alpha-6 & lt; /version & gt; & lt; /dependency & gt; & lt; /dependencies & gt; DevTools is a class that provides several methods to treat developer options, such ascreateSession, addListener, close and send. The getDevTools ()method retrovert the newDevToolsaim which allows you tosend() the built-in Selenium commands for CDP. ChromeDriver driver=new ChromeDriver () OR EdgeDriver driver=new EdgeDriver () DevTools devTools = driver.getDevTools (); devTools.createSession (); You can pass Optional.empty () in case you do not have to specify any web. Map & lt; String, Object & gt; headers =newHashMap & lt; & gt; (); headers.put (& # 8220; Authorization & # 8221;, & # 8220; Basic & # 8221; + encodeToString); driver.get (& # 8220; https: //the-internet.herokuapp.com/basic_auth & # 8221;); public class BasicAuthSelenium4 { ChromeDriver driver; @ BeforeTest public vacuum setup () { // Setup Chrome driver WebDriverManager.chromedriver () .setup (); driver = new ChromeDriver (); driver.manage () .window () .maximize (); driver.manage () .timeouts () .implicitlyWait (30, SECONDS); // Authentication username & amp; password String username = & # 8220; admin & # 8221;; String password = & # 8220; admin & # 8221;; // Get the devtools from the running driver and create a session DevTools devTools = driver.getDevTools (); devTools.createSession (); // Enable the Network domain of devtools devTools.send (Network.enable (Optional.empty (), Optional.empty (), Optional.empty ())); String auth = username + & # 8220;: & # 8221; + word; // Encoding the username and password expend Base64 String encodeToString = Base64.getEncoder () .encodeToString (auth.getBytes ()); System.out.println (& # 8220; Encoded String: & # 8221; + encodeToString); // Pass the net header as Authorization: Basic & lt; encoded String & gt; Map & lt; String, Object & gt; headers = new HashMap & lt; & gt; (); headers.put (& # 8220; Authorization & # 8221;, & # 8220; Basic & # 8221; + encodeToString); devTools.send (Network.setExtraHTTPHeaders (new Headers (headers))); } @Test public void launching () { driver.get (& # 8220; https: //the-internet.herokuapp.com/basic_auth & # 8221;); String schoolbook = driver.findElement (By.cssSelector (& # 8220; div.example p & # 8221;)) .getText () .trim (); Assert.assertEquals (text, & # 8220; Congratulations! You must have the proper credentials. & # 8221;); } @ AfterTest public nothingness tearDown () { driver.quit (); } } This article explains the different ways to automate Window login popups in Selenium script. Passing credentials in the URL itself is an insecure approach as it may expose credentials in insecure setting. Auto IT expect extra facility and configuration to work with the Selenium script. So, if we liken all three, utilise ChromeDevTools Protocols is the best approach so far. It is crucial to test the login popup on different Windows OS and different browser. And this can be achieved by running your tests on BrowserStack as it has all the latest Windows OS and browsers available to test your merchandise. # Ask-and-Contributeabout this topic with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Related Product
Handling Login Popups in Selenium WebDriver and Java
Overview
What is an Authentication Pop-up
Passing credentials in the URL
Using AutoIt puppet
How to Install AutoIt
Creating AutoIt book
Using ChromeDevTools Protocols API
Steps to use Chrome DevTools
devTools.send (Network.enable (Optional.empty (), Optional.empty (), Optional.empty ()));
String auth = username + & # 8220;: & # 8221; + word;
String encodeToString = Base64.getEncoder () .encodeToString (auth.getBytes ());
Related Guides
Automate This With SUSA
Test Your App Autonomously