Automating Windows Controls in Selenium

Reading Time: 3 minutes

Welcome again!
Ever think of handling Windows Controls via Selenium?
Many times we come across the situation where we need to click on a button and a new pop up window appears, for instance, in case of File upload. We need to switch to that window which is either our drive or the local machine.
Selection a file from a local machine or drive does not belong to any web browser.
As we know, Selenium works with the only web-based application, so, in this blog, we are going to see how we can automate Windows Controls using selenium.

Types of Windows Controls

There are two types of Window controls :

1. Windows authentication pop-ups

Many companies put proxy settings to access servers. If you try to open the server, it asks for valid credentials and do log in to have access to that server. If we don’t handle the popup, we couldn’t do further testing
Please note that window pop-ups are NOT similar to javascript pop-ups. Simple authentication is shown below.

Simplest way to handle this is to append username and password in the site URL. It automatically enter the credentials that way.



String authCred = "http://" + komal + ":" + Tester#123 + "@" +;

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

2. Handling file upload from Windows

File upload in Web applications can be achieved by AutoIT.

What is AutoIT?

You might have come across the real-time scenarios where you need to upload a file using the “Choose File” button. 

Basically, “Choose File” can be opened up using Selenium but the process after that is achieved using a handler called AutoIT.

AutoIt is an open-source tool. It is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying “runtimes” required!

SciTE is the editor we use to write our script in AutoIT.

Steps to download and install AutoIT for Windows

  • First, Download AutoIT from here
  • Simply, Run this set up file.
  • Then, Install it by clicking next and go through all the installing process
  • After that, A folder will be created with program file.
  • Now, Open the AutoIT folder and find Scite editor
  • Finally, in SciTE write the following code.

Code for Handling Windows Controls (Upload File) :

package com.knoldus.snap3;
import java.util.HashMap;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;

public class FileUpload {

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

		// TODO Auto-generated method stub

		String downloadPath=System.getProperty("user.dir");
		System.setProperty("", "/home/knoldus/Downloads/Automation/chromedriver_linux64/chromedriver");
		HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
		chromePrefs.put("profile.default_content_settings.popups", 0);
		chromePrefs.put("download.default_directory", downloadPath);
		ChromeOptions options=new ChromeOptions();
		options.setExperimentalOption("prefs", chromePrefs);
		WebDriver driver=new ChromeDriver(options);
		WebDriverWait wait=new WebDriverWait(driver,10);
		wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Download Now")));
		driver.findElement(By.linkText("Download Now")).click();
		File f=new File(downloadPath+"/");
				System.out.println("file deleted");

To find out How logs can be inserted in a selenium code click here.



Written by 

Nearly 3 years of experience in automation testing, I call myself an automation enthusiast. I can create, execute automated test scripts using framework guidelines and best practices to ensure wider and efficient end-to-end automation coverage. Simultaneous experience in Defect tracking and bug reporting through JIRA