Tuesday 14 April 2020

AutoIT script for windows based chrome authentication in Selenium or Cucumber

Hi,

The following AutoIt script can be used for windows based chrome authentication.

1. Open the website in chrome with windows based pop-up.
2. Open the AutoIT tool and move the "Finder Tool" on to the window.
3. Make a note of "Title" and "Class" of the window.
4. Use the following script with values updated with the "Title" and "Class".
5. Save the file, for example : atuoit_chrome_credentials.au3  (extension should be .au3)
6. Compile the script (right click from the location where the file is saved and compile).
7. Compile generates .exe file , in this case it is : atuoit_chrome_credentials.exe

Call the .exe file before the website get loaded in java file


Runtime.getRuntime().exec("\path to the .exe file\"+"autoit_chorme_credentials.exe");


AutoIT code snippet


;RequireAdmin ; unsure if it's needed
;$iSleep = 2000
Opt("WinSearchChildren", 1)
$sUsername = "admin"
$sPassword = "PaSSWorD2%"
Sleep(1000)
For $i = 1 To 20 Step 1
    Sleep(3000)
    $sTitle = WinGetTitle("Sign in")
    If $sTitle = "sadakar.network.com - Google Chrome" or WinWaitActive("[CLASS:Chrome_WidgetWin_1]")  or WinWaitActive("Sign in") Then
        Send($sUsername)
        Send("{TAB}")
        Send($sPassword,1);$SEND_RAW (1)
        Send("{TAB}")
        Send("{ENTER}")
        Exit 0
    Else
        ContinueLoop
    EndIf
Next
Exit 1


How to find Title and Class from AutoIt tool ? 



Auto reads the credentials while the program runs for chrome based windows authentication pop-up.



- Sadakar Pochampalli

No comments:

Post a Comment