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 in Selenium by Pragati
46 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 by Abha
• 15,680 points

Related Questions In Selenium

0 votes
1 answer

What are the different components of Selenium?

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

answered Jan 7 in Selenium by Fuji
126 views
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 in Selenium by Anvi
• 9,990 points
93 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,050 points
250 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,130 points
621 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,130 points
243 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 in Selenium by Abha
• 15,680 points
53 views
0 votes
1 answer