How to Handle Browser Authentication popup using Selenium Webdriver

driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://52.19.191.249/aur/");
driver.switchTo().alert().sendKeys("username");
driver.switchTo().alert().sendKeys("password");
driver.switchTo().alert().accept();

Getting message as no alert open

Upvotes: 0

Views: 2826

Answers (3)

Mayank Mani Jha
Mayank Mani Jha

Reputation: 1

Try using autoit: [its simple and effective]

The code goes something like ::

from selenium import webdriver
import autoit
driver= webdriver.Chrome()
driver.get("http://sitewithpopup.com")
autoit.win_wait_active("",30) 
autoit.send("Username{TAB}")
autoit.send("Password{Enter}")

Since the autoit will type whereever your cursor is and by default the cursor is on the userID field so you can make use of it.

Upvotes: 0

Dmitrii Novikov
Dmitrii Novikov

Reputation: 31

Since driver.switchTo().alert() doesn't wait for alert loaded, you need to wait for it. See https://stackoverflow.com/a/12639803/8609512

P.S. You can check it by adding a Thread.sleep(2000); for example, before driver.switchTo().alert().sendKeys("username"); sentence -- sleeps are usually a bad practice for test automation, but sometimes it could be helpful in debugging.

Upvotes: 3

Tried with this syntax and worked driver.get("http://Username:[email protected]/aur/") ;

Upvotes: 0

Related Questions