What are the different ways of handling authentication popup window using Selenium?

0 votes
What are the different ways of handling authentication popup window using Selenium?
May 28, 2019 in Selenium by Pragati
1,039 views

1 answer to this question.

0 votes

Hey Pragati, authentication popups can be handled in 3 different ways:

  1. By passing user credentials in URL: Append your username and password with the URL. Syntax is: http://Username:Password@SiteURL; For eg:
    • String URL = "http://" + abha_r + ":" + myPassword + "@" + www.prime.amazon.com;
      driver.get(URL);
      Alert alert = driver.switchTo().alert();
      alert.accept();
  2. By using AutoIT: Use AutoIT script to send username and password. For eg:

    • public static void login(String email, String password) throws Exception{
      
      driver.get(URL);
      WinWaitActivate("Authentication Required","")
      Send("abha_r{TAB}myPassword{ENTER}")
      
      Runtime.getRuntime().exec("C:\\Download\\AutoItFiles\\ExecutableFiles\\FirefoxBrowser.exe");
      driver.findElement
      
      loginpage.setEmail(email);
      loginpage.setPassword(password);
      loginpage.clickOnLogin();
      }
       
  3. By using Alerts in Selenium: We can use following lines of code to handle popup window using Alerts. For eg:

    • 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();
answered May 28, 2019 by Abha
• 27,760 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

What are the different components of Selenium?

Selenium is a testing tool and comprises ...READ MORE

answered Jan 7, 2019 in Selenium by Fuji
368 views
0 votes
2 answers
0 votes
2 answers

What are the benefits of using TestNG with Selenium?

Hi Falguni, some of the benefits of ...READ MORE

answered May 31, 2019 in Selenium by Anvi
• 14,010 points
163 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
1,563 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,870 points
1,496 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,870 points
1,277 views
0 votes
1 answer

What are locators in Selenium and what are the different types of it?

Hi Divya, in Selenium Locators define an ...READ MORE

answered May 7, 2019 in Selenium by Abha
• 27,760 points
190 views
0 votes
1 answer

What are the main disadvantages of using implicit wait in Selenium?

Hey Aaron, the main disadvantage of implicit ...READ MORE

answered May 31, 2019 in Selenium by Abha
• 27,760 points
530 views