Authentication dialog with selenium and autoit

selenium

Some websites require authentication id and password when we launch them.
For authentication window we use autoit.
we can download autoit from here

After that we need to install it in our system.
Now we need to write a autoit scriptto handle the authentication window.

WinWaitActive("Authentication Required")
Send("user-name")
Send("{TAB}")
Send("password")
Send("{ENTER}")

for our sample example we use this script –

WinWaitActive("Authentication Required")
Send("tanmay")
Send("{TAB}")
Send("sarkar")
Send("{ENTER}")

save this file as “your-file-name.au3”

Right click on the file and chose “Compile Script (x86)” option and it will make “your-file-name.exe”

now write the sample java code to use it –

package com.webdriver_04;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Auth {

	public WebDriver driver;
	private String baseUrl;
	
	public static void main(String[] args) {
		Auth au = new Auth();
		au.launch_browser();
	}
	public void launch_browser(){
		try{
		baseUrl = "http://demo.tanmaysarkar.com/authentication/";
			   

		Process P = Runtime.getRuntime().exec("Z:\\your_path\\your-file-name.exe");
		driver = new FirefoxDriver();
		driver.get(baseUrl);	 
		P.destroy(); 	
		System.out.println("Just provide the User name and Password in authentication window");
		driver.findElement(By.id("ts_first_name")).sendKeys("tanmay");
		System.out.println("Enter the first name");
		driver.findElement(By.id("ts_last_name")).sendKeys("sarkar");
		System.out.println("Enter the last name");
		driver.findElement(By.id("ts_address")).sendKeys("my address");
		System.out.println("Enter the last name");
		driver.quit();
		}
		catch (Exception ex)
		{
			ex.getMessage();
		}
	}
}

Note: I make this URL ( http://demo.tanmaysarkar.com/authentication/ ) for demo testing of authentication. You may also use this link for your understanding.
The user id is – “tanmay” without quote and password is “sarkar” without quote.
Hope it will help you to try a hands on of this topic.

If you don’t want to use autoit, can check this option too.

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *