简体   繁体   中英

How to handle authentication popup window in UI automation using Selenium in C#

How to handle authentication popup window in UI automation using Selenium in C#

I am authoring a UI test that navigate to a website Home page. As the website internally access another site. Selenium on Firefox displays a authentication required popup window.

How do I handle the popup window using Selenium driver to enter the username and password on the popup window?

you can use like below:-

driver.get("http://UserName:Password@Example.com");

Give your username in place of username, same for password and change example.com with your website

OR there is one more method but it is in java you can convert it into C# by taking it's reference.

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

Hope it will help you :)

Paste this in your .config file

add key= URL value="http:// username : password @ pasteyoururl "

paste this in your c# script

string `variable` = ConfigurationManager.AppSettings["**URL**"];
driver.Navigate().GoToUrl(**variable**);

Try the above mentioned code, sure it will work.

This code will only work only if you read key from app.config/web.config

string siteUser = "testUser";
string sitePass = "testPass";
string siteUrl = "localhost:1980"
string format = @"https://{0}:{1}@{2}/site";
string authURI = String.Format(format, siteUser, sitePass, siteUrl);
driver.Navigate().GoToUrl(authURI);

This is what worked for us

在导航应用程序 url 时,使用如下所示的应用程序 url 传递您的用户名和密码:

http://username:passwork@applicationURL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM