MKay
MKay

Reputation: 836

How to handle browser authentication pop up within application using selenium webdriver

I am automating test cases for an application which requires an authentication to launch homepage. I am using below code to make it work.

String url = "http://i.user:i.password@baseURL_1/home";
driver.get(url);

Once I am inside the application , there is another link called "workflow" , clicking on which opens another application of same system. i.e. it redirects to http://baseURL_2/home.

While opening page from second application , browser(Chrome) authentication window re-appears. How do I handle it in automation script?

Upvotes: 0

Views: 747

Answers (3)

Bulut Kartal
Bulut Kartal

Reputation: 103

var alert = driver.SwitchTo().Alert();
alert.SetAuthenticationCredentials("username", "password");
alert.Accept();

Upvotes: 0

Kapil
Kapil

Reputation: 407

Try below code :-

WebDriverWait wait = new WebDriverWait(driver, 10);      
Alert alert = wait.until(ExpectedConditions.alertIsPresent());     
alert.authenticateUsing(new UserAndPassword(username, password));

Upvotes: 1

Danny
Danny

Reputation: 287

I see you've tried to pass the username and password within the URL. I had a similar issue a while back, the resolution for me was to whitelist my IP, this means the website wont request a username and password when you visit.

Hope this helps.

Upvotes: 0

Related Questions