How to handle Windows Authentication | Selenium Webdriver Tutorial with c# |Selenium C# training

Selenium C# Training Forum

How to handle Windows Authentication

D
Durga Ponnapalli Post on 24/12/2018

Hi Team,

I am stuck browser authentication, as most of .net based applications are intranet applications and need Single Sign on to validate some testing by signin as different user.
I have tried AutoIT integrating into selenium but couldnt proceed with signin into the application, am trying in chrome and IE still have issues.


Please Look into the issue and support me!!

Thanks,
Durga.

G

Instructor

gunjan Reply on 25/12/2018

Can you please share the code 

D
Durga Ponnapalli Reply on 25/12/2018

Sure will share it with you

public static void Main(string[] args)

{


try
{

IWebDriver driver = new ChromeDriver();

driver.Navigate().GoToUrl("URL");
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(30);
Thread.Sleep(5000);
driver.FindElement(By.XPath("//div[@id='bs-example-navbar-collapse-1']/ul[2]/li/a")).Click();
Thread.Sleep(5000);
//calling before clcking
userCredentials();
//Process.Start(@"C:\Users\WindowsAuth.exe");
driver.FindElement(By.XPath("//li/a[@href='/TimeOffRequest/Account/SignInAsDifferentUser']")).Click();

Thread.Sleep(5000);

}
catch(Exception Ex)
{
Console.WriteLine("Message" + Ex.Message);
Console.ReadKey();
}





}
public static void userCredentials()
{
AutoItX3 aut = new AutoItX3();

//aut.WinWait("Sign in", "Chrome Legacy Window", 20);
//aut.WinActivate("Sign in");
//aut.Send("username");
//aut.Send("{TAB}", 0);
//aut.Send("password");
//aut.Send("{Enter}", 0);



I tried making it as executable..then its working by taking username and password but couldnt proceed by clicking on sign in..without AutoIT executable i tried with autoIT class that is also not working

Please help me in proceeding further

Thanks,
Durga.

G

Instructor

gunjan Reply on 07/01/2019

consider this sample autoit code for parametrizing the parameters:

ControlFocus("Open","","[CLASS:ComboBox; INSTANCE:1]")
ControlSetText("Open","","[CLASS:Edit; INSTANCE:1]",$CmdLine[1])
ControlClick("Open","","[CLASS:Button; INSTANCE:1]")

D
Durga Ponnapalli Reply on 07/01/2019

Hi Gunjan,

 

Thanks for your response. Is this code to make it as executable or in selenium we can write in this way..can you explain the notations to me so that can apply as required.

 

Thanks,

Durga.

D
Durga Ponnapalli Reply on 08/01/2019

Can you elaborate it for me please, I couldnt understand completely the code parameters and used it as SciEditor to make it as exe and its not working..please help

G

Instructor

gunjan Reply on 08/01/2019

Its explained in the Module-14 video

D
Durga Ponnapalli Reply on 13/01/2019

Hi Gunjan,

 

 

Thanks for your response. I watched the videos in module 14 and found all the notations, but still while trying SSO with the above syntax its not working, So i tried below i was able to enter the username and password but Sign in am not able to handle either by controlClick or Send{"ENTER"} none are working to click the Sign In and enter into the required website. I tried by giving wait times and everything, But still no luck

 

Please look into the code and give you suggestions on this. I got stuck badly on this and couldnt proceed for my testing becz of this blocker issue.

 

Thanks,

Durga.