How To Handle Authentication Popup Window Using Selenium WebDriver
Handling Authentication Popup Window:
In this post, we see how to handle Authentication Popup using Selenium WebDriver.
What is Authentication Popup window and why these Authentication Popup windows showed up while opening few websites.
Authentication popup window looks like the below mentioned image.
Let’s see “How To Handle Authentication Popup using Selenium WebDriver”:
Companies have their own proxy settings to access some servers. If you open a server in the browser a popup window will load and force you to enter user credentials to do login to access the server. Even while accessing the same server using selenium script we need to handle the popup before hand accessing the server. If we can’t handle this, we couldn’t do further testing.
We could handle this type of authentication pop up in multiple ways. Let’s see in detail.
Approach 1: Handling Authentication/Login Popup Window using Selenium WebDriver
By passing user credentials in URL. Its simple, append your username and password with the URL.
e.g., http://Username:Password@SiteURL
http://rajkumar:myPassword@www.softwaretestingmaterial.com
here, Username is rajkumar
Password is myPassword
SiteURL is www.softwaretestingmaterial.com
Sample code:
String URL = "http://" + rajkumar + ":" + myPassword + "@" + www.softwaretestingmaterial.com; driver.get(URL); Alert alert = driver.switchTo().alert(); alert.accept();
Approach 2: Handling Authentication/Login Popup Window using Selenium WebDriver
By using AutoIt, we could handle authentication pop up.
Also Read:
Sample AutoIT Script:
WinWaitActivate("Authentication Required","") Send("rajkumar{TAB}myPassword{ENTER}")
Sample Java Code:
public static void login(String email, String password) throws Exception{ driver.get(URL); //Passing the AutoIt Script here Runtime.getRuntime().exec("D:\\Selenium\\workspace\\AutoItFiles\\ExecutableFiles\\FirefoxBrowser.exe"); driver.findElement loginpage.setEmail(email); loginpage.setPassword(password); loginpage.clickOnLogin(); }
Approach 3: Handling Authentication/Login Popup Window using Selenium WebDriver
By using Alerts in Selenium, we could handle authentication pop up.
driver.switchTo().alert(); //Selenium-WebDriver Java Code for entering Username & Password as below: driver.findElement(By.id("userID")).sendKeys("userName"); driver.findElement(By.id("password")).sendKeys("myPassword"); driver.switchTo().alert().accept(); driver.switchTo().defaultContent();
I am working in banking project.I am unable to switch to window which is required for higher authorisation.
Following are steps
1. Login to application
2.Do payment transaction
3. Window displays on same the page generating number which needs to be captured.
I am unable to do 3rd step
I have tried driver.switchto().Window(handle)
HI,
I am trying the secodn approach it works fine with Firefox and IE but not teh chrome, For chrome The window title shows Sign in and i built autoit script for the same.
WinWaitActive(“Sign in “,””,”20″)
If WinExists(“Sign in “) Then
Send(“qatest”)
Send(“{TAB}”)
Send(“test123”)
Send(“{ENTER}”)
EndIf
Please help how to handle windows authentication for chrome