Windows authentication appears in Chrome browser

I am trying to handle basic authentication for my Selenium web earring scripts using AutoIt. I wrote a script for Firefox and Internet Explorer, but it does not work for Chrome.

When I tried to authenticate with Chrome using the AutoIt Window Information Tool , it turned out to be empty. I am using the following AutoIt script:

WinWaitActive("Authentication Required","","120") If WinExists("Authentication Required") Then Send("username{TAB}") Send("password{Enter}") EndIf 

Any pointers to make this work would be helpful. I do not use username@password :google.com because authentication pop-ups appear when redirecting.

+6
source share
4 answers

I managed to set AutoIt to a window by text, and not the window title. AutoIt Window Information Tool did not recognize the title, but recognized the visible text.

So, I changed the script to:

 WinWaitActive("","Authentication Required","120") If WinExists("","Authentication Required") Then Send("username{TAB}") Send("password{Enter}") EndIf 

It worked fine.

+3
source

First of all, you do not need AutoIt, you can just use the windows API. Secondly, the basic Chrome validation dialog is not a traditional window, so you cannot handle it (try using Spy ++). The only reason this will work is not to bring another window to the front before calling SendKeys. You need to find the parent window of Chrome, which could be something like โ€œGoogle Chrome URLโ€, move it to the front and then send the keys. Here is an example:

 using System; using System.Runtime.InteropServices; using System.Windows.Forms; [DllImport("User32.dll")] private static extern bool SetForegroundWindow(IntPtr point); [DllImport("user32.dll")] private static extern IntPtr FindWindow(string className, string windowTitle); public static void SendBasicAuthentication(string username, string password, string windowTitle) { var hwnd = FindWindow(null, windowTitle); if (hwnd.ToInt32() <= 0 || !SetForegroundWindow(hwnd)) return; SendKeys.SendWait(username.EscapeStringForSendKeys()); SendKeys.SendWait("{TAB}"); SendKeys.SendWait(password.EscapeStringForSendKeys()); SendKeys.SendWait("{ENTER}"); } static string EscapeStringForSendKeys(this string input) { // https://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx // must do braces first return input.Replace("{", "{{}") .Replace("}", "{}}") .Replace("^", "{^}") .Replace("%", "{%}") .Replace("~", "{~}") .Replace("(", "{(}") .Replace(")", "{)}") .Replace("[", "{[}") .Replace("]", "{]}"); } 

Hope this helps.

+2
source

I used your script and expanded it a bit for my needs. The user and password are not hardcoded and can be set using the command line or user input. The script needs to be run only once.

 If(Not IsArray($CmdLine) Or $CmdLine[0] < 2) Then $user = InputBox ("User", "Please enter your user", "") $pass = InputBox ("Password", "Please enter your password", "", "*M") Else $user = $CmdLine[1] $pass = $CmdLine[2] EndIf While(True) WinWaitActive("", "Authentifizierung erforderlich","120") If WinExists("", "Authentifizierung erforderlich") Then Send($user) Send("{TAB}") Send($pass) Send("{Enter}") Sleep(1000) EndIf WEnd 

The next step would be to find out what language is installed in chrome, and set the name of the window, depending on it.

0
source

Please try this, mine works, I got AutoItX from nuget:

 AutoItX.WinWait("title of your browser", "", 9); AutoItX.WinActivate("title of your browser"); AutoItX.Send("userid"); AutoItX.Send("{TAB}", 0); AutoItX.Send("password"); AutoItX.Send("{Enter}", 0); 
0
source

Source: https://habr.com/ru/post/955902/


All Articles