I am trying to write UI Automation for a Portal but while Authentication Chrome after entering User name a Pop up comes which can not be handled by selenium c#
I have tried using https://username:password{siteurl}.com
But it didn't work. Also Auto IT nuget is not working. Any suggestions will be really helpful
PFB the screenshot for the same.
CodePudding user response:
If the popping prompt is not part of the HTML page, but a Windows alert, you can try using the keyboard:
new Actions(driver).SendKeys("User_Name").Perform();
new Actions(driver).SendKeys(Keys.Tab).Perform();
new Actions(driver).SendKeys("Password_here").Perform();
new Actions(driver).SendKeys(Keys.Tab).Perform();
new Actions(driver).SendKeys(Keys.Enter).Perform();
Basically you just type the user_name and password and hit the Enter key using Selenium.
CodePudding user response:
You can't try using a "robot" keyboard which just types in the keyboard. There is no need for the element to be inside the HTML page, as long as you know the prompt is focused:
Install the NuGet InputSimulator:
InputSimulator sim = new InputSimulator();
sim.Keyboard.TextEntry("User123");
sim.Keyboard.KeyPress(VirtualKeyCode.TAB);
sim.Keyboard.TextEntry("Password123");
sim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
This way you just "hit" the keyboard. You code works regardless of the webpage.