Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle login pop up window using Selenium WebDriver?

How to handle the login pop up window using Selenium Webdriver? I have attached the sample screen here. How can I enter/input Username and Password to this login pop up/alert window?

Thanks & Regards, enter image description here

like image 708
shiva oleti Avatar asked Jul 17 '12 12:07

shiva oleti


2 Answers

Use the approach where you send username and password in URL Request:

http://username:[email protected] 

So just to make it more clear. The username is username password is password and the rest is usual URL of your test web

Works for me without needing any tweaks.

Sample Java code:

public static final String TEST_ENVIRONMENT = "the-site.com"; private WebDriver driver;  public void login(String uname, String pwd){   String URL = "http://" + uname + ":" + pwd + "@" + TEST_ENVIRONMENT;   driver.get(URL); }  @Test public void testLogin(){    driver = new FirefoxDriver();    login("Pavel", "UltraSecretPassword");    //Assert... } 
like image 54
Pavel Janicek Avatar answered Sep 22 '22 15:09

Pavel Janicek


This should works with windows server 2012 and IE.

var alert = driver.SwitchTo().Alert();  alert.SetAuthenticationCredentials("username", "password");  alert.Accept(); 
like image 40
Wahab Majboor Avatar answered Sep 20 '22 15:09

Wahab Majboor