Search code examples
seleniumselenium-webdriverautoit

Handling Windows authentication pop up


Below is my AutoIt script (UI3_Authentication.au3) for handling a Windows authentication pop up.

AutoItSetOption("WinTitleMatchMode","2")  
WinWait("Authentication Required")   
$title = WinGetTitle("Authentication Required") ; retrives whole window title   
$UN=WinGetText($title,"User Name:")  
ControlSend($title,"",$UN,"test");Sets Username  
$PWD=WinGetText($title,"Password:")  
Send("{TAB 1}")  
ControlSend($title,"",$PWD,"test1234");Sets PWD  
Send("{ENTER}")  

Below is my Selenium code call to the above AutoIt exe file.

package tests;

import java.io.IOException;  
import org.openqa.selenium.WebDriver;  
import org.openqa.selenium.firefox.FirefoxDriver;  

public class Handling_Windows_Based_Prompt {

public static void main(String[] args) throws IOException{  
WebDriver c1 = new FirefoxDriver();  
c1.get(“http://www.test.com”);  
        Runtime.getRuntime().exec("C:\\POM_Newdemo\\EF_Automation_Demo\\UI3_Authentication.exe");

}  
}

When I run the above Selenium file, it opens up the page and authentication pop up. But it is not inserting username and password; it waits for user input instead.


Solution

  • I resolved this. Actually, it was my bad. Previously, my code was like this:

    c1.get(“http://www.test.com”);  
        Runtime.getRuntime().exec("C:\\POM_Newdemo\\EF_Automation_Demo\\UI3_Authentication.exe");
    

    I Added autoit code before my get() as follows, and it worked:

    Runtime.getRuntime().exec("C:\\POM_Newdemo\\EF_Automation_Demo\\UI3_Authentication.exe");
    c1.get(“http://www.test.com”);