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

Related Product

Handling Login Popups in Selenium WebDriver and Java

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.

Overview

  • Definition of Authentication Popup in Selenium: A proxy porthole is the communication terminus on a proxy server that manages the stream of requests between client device and the internet.
  • Functionality of Authentication Popup in Selenium: It ensures smooth, secure, and efficient routing of traffic, countenance access to online resources via the proxy host.

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.

What is an Authentication Pop-up

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:

Passing credentials in the URL

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:

Using AutoIt puppet

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.

How to Install AutoIt

  • Go to the official download page ofAutoIt and download the AutoIt software zip file.
  • Move both the files to any preferred location in your scheme and extract the AutoIt zip file. There should be two executables now “ autoit-v3-setup.exe ” and “ SciTE4AutoIt3.exe ”
  • Finish installation of both the files in the system and browsing till “ C: \Program Files (x86) \ AutoIt3 ” to discover the AutoIt pamphlet as AutoIt executables are 32 bit.

Creating AutoIt book

  • Browse to “ C: \Program Files (x86) \AutoIt3\SciTE ” and double-click “ SciTE.exe ” to launch AutoIt editor.
  • Enter the below codification to pass username and password in AutoIt editor and save the file with propagation .au3

Example: Login.au3

Send (& # 8220; admin & # 8221;)

Send (& # 8220; {TAB} & # 8221;)

Send (& # 8220; admin & # 8221;)

Send (& # 8220; {ENTER} & # 8221;)

  • Right-click the make script (Login.au3) and choose “ Compile script (x64) / Compile handwriting (x64) “ depending on your Windows configuration and observe that “ Login.exe ” is yield.
  • Now after the driver.get () method you can put the AutoIt executable path as below

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

}

}

Using ChromeDevTools Protocols API

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.

Steps to use Chrome DevTools

  • ChromeDev Tools works only for Chromium-based browser such as Google Chrome and Microsoft Edge. So, we demand to create a driver instance of ChromeDriver or EdgeDriver.

ChromeDriver driver=new ChromeDriver ()

OR

EdgeDriver driver=new EdgeDriver ()

  • Get the dev puppet from following code and create a new session

DevTools devTools = driver.getDevTools ();

devTools.createSession ();

  • Enable the web land of dev creature
devTools.send (Network.enable (Optional.empty (), Optional.empty (), Optional.empty ()));

You can pass Optional.empty () in case you do not have to specify any web.

  • Concatenate username and password separated by colon and store it any String target
String auth = username + & # 8220;: & # 8221; + word;
  • Encode the username and countersign using Base64 from java.util package
String encodeToString = Base64.getEncoder () .encodeToString (auth.getBytes ());
  • Finally pass the network coping as Authorization: Basic & lt; encoded twine & gt; using HashMap

Map & lt; String, Object & gt; headers =newHashMap & lt; & gt; ();

headers.put (& # 8220; Authorization & # 8221;, & # 8220; Basic & # 8221; + encodeToString);

  • Now as the head is set, we can invoke the website by driver.get ()

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.

Tags
18,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free