In case of login into an application in selenium, an alert pop may be displayed authenticating for user credential. The pop-up can be web based or windows based popup.
Web Based Authentication pop-up can be handled using alert class as shown below:
// provide a wait condition for alert to be present
WebDriverWait wait = new WebDriverWait(driver, 30);
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
//Using alert.authenticateUsing, provide username and password for http alert popup
alert.authenticateUsing(new UserAndPassword( ** username ** , ** password ** ));
Or else, can try the below code and see it works:
driver.Navigate().GoToUrl("http://UserName:Password@testingmail.com");
This was about web-based pop-up, In case a windows pop-up appears asking for username and password, An autoIT script can be created to handle the windows pop-up.
- Create an au3 file for handling the pop-up.
- Compile the au3 file using AutoIT script to exe converter.
- Run the autoIT exe file using below code in selenium.
Runtime.getRuntime().exec("d:\\AuthenticateAutoIt.exe");