Ashok
Ashok

Reputation: 1906

How to fill Authentication Required popup in chrome with Selenium C#

I'm trying to open a intranet website with Selenium which redirects to another link for login and gets back to original URL on valid login. For example - When I start webdriver and navigate to original site URL https://DemoOriginalWebsite.Com the browser gets redirected to https://Validateyourselfbeforeaccessing.com:9030 and shows below popup window to enter user id and password.

Popup window

I tried to pass credentials as below but didn't work.

Try 1 : http://username:[email protected]

Try 2 : https://username:pswdValidateyourselfbeforeaccessing.com:9030

The authentication URL can't be accessed directly.

My actual code:

IWebDriver chromeDriver;
ChromeOptions options = new ChromeOptions();
options.AddArgument("disable-infobars");
options.AddUserProfilePreference("credentials_enable_service", false);        
options.AddUserProfilePreference("profile.password_manager_enabled", false);
chromeDriver = new ChromeDriver(options);
chromeDriver.Manage().Window.Maximize();     chromeDriver.Navigate().GoToUrl(@"http://username:[email protected]");

Any suggestions please.

Upvotes: 0

Views: 8232

Answers (2)

Ashok
Ashok

Reputation: 1906

Here is how I figured out.

1 - Added AutoIt NuGet package to project.

2 - Used as below:

IWebDriver driverIE = new InternetExplorerDriver();
driverIE.Manage().Window.Maximize();
driverIE.Navigate().GoToUrl(@"https://DemoOriginalWebsite.Com");
AutoItX.ControlFocus("Windows Security", "", "Edit1");
AutoItX.ControlSetText("Windows Security", "", "Edit1","userid");
AutoItX.ControlFocus("Windows Security", "", "Edit2");
AutoItX.ControlSetText("Windows Security", "", "Edit2", "password");
AutoItX.ControlClick("Windows Security", "", "Button2");
//Do your work.
driverIE.Dispose();

Tutorials I followed. Tutorial 1 and Tutorial 2

Upvotes: 2

Alok
Alok

Reputation: 1561

you will have to use AutoIT. Install AutoIT, write the script in AutoIT and export it as an .exe file. This .exe you will have to call in your selenium

WinWait("Untitled - Google Chrome", "" , 10)) //This will wait for 10 seconds for window with the specified title
WinActivate("Untitled - Google Chrome"); // This will send the focus of the cursor to the window with the specified title
Send("username");

//1st argument : moves the cursor's focus from Username textbox to Password text box.  
//2nd argument : false,  over here tell that it is not a text but raw key
Send("{TAB}", false); 
Send("password");
Send("{Enter}", false);// this will mimic the action of pressing enter button.

Upvotes: 1

Related Questions