Xenox Posted November 30, 2016 Posted November 30, 2016 I have created an exe file named "SolveAuthPopup.exe" using AutoIT, to solve the Firefox authentication pop up window problem, and trigger it using Selenium Webdriver. However, I have encountered a weird problem here. When I run the selenium code on 1st time, it does not execute SolveAuthPopup.exe. However, when I run the selenium code on 2nd time, it does execute SolveAuthPopup.exe. And, after that, when I manually open the Firefox browser and browse to www.example.com, the username & password are auto-filled up and login (just like running the SolveAuthPopup.exe). Summary : 1st time execute Selenium code ---> SolveAuthPopup.exe does not run 2nd time execute Selenium code ---> run because of the 1st time execution Manually browse the website ---> run because of the 2nd time execution Anyone has any idea on why this issue happens and how to fix this weird issue ? ********************my AutoIT exe file named "SolveAuthPopup.exe" #Region ----code below is to simulate 1) enter username & password , 2) press OK button WinWaitActive("Authentication Required","") Send("UserName{TAB}PassWord") MouseClick("left",639,423,1) MouseMove(1,1,1) #EndRegion *********************my selenium code oDriver = new FirefoxDriver(); //Go to website that will prompt authentication popup window oDriver.get("www.example.com"); //Run the exe file that compiled from AutoIT to simulate enter username&password into authentication pop up window Runtime.getRuntime().exec("H:\\Automation Script\\Selenium\\SolveAuthPopup.exe");
JohnOne Posted November 30, 2016 Posted November 30, 2016 Possibly could be an issue with page not fully loaded when window is active. To test that theory, add a sleep of varying lengths. #Region ----code below is to simulate 1) enter username & password , 2) press OK button $iSleep = 2000 WinWaitActive("Authentication Required","") Sleep($iSleep) Send("UserName{TAB}PassWord") MouseClick("left",639,423,1) MouseMove(1,1,1) #EndRegion AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Xenox Posted November 30, 2016 Author Posted November 30, 2016 JohnOne, thanks for your reply. I have tried with 15 seconds delay time. However, it is still the same, not being triggered at the 1st time code execution and 2nd time code execution / manual browse to the website, it triggers (and it fills in username & password after 15 seconds delay). Also I had tried "sleep" in Selenium code before, it does not work too. So, the cause might not be "page not fully loaded when window is active." #Region ----code below is to simulate 1) enter username & password , 2) press OK button $iSleep = 15000 WinWaitActive("Authentication Required", "") Sleep($iSleep) Send("Username{TAB}Password") MouseClick("left",639,423,1) MouseMove(1,1,1) #EndRegion
JustSomeone Posted November 30, 2016 Posted November 30, 2016 (edited) Let me jump in, Put this on top on your script : Opt("WinSearchChildren",1) then WinWaitActive("Authentication Required", "") Send("Username{TAB}Password{ENTER}") And you are good to go EDIT: for more info visit the help file, or https://www.autoitscript.com/autoit3/docs/functions/AutoItSetOption.htm#WinTitleMatchMode Edited November 30, 2016 by JustSomeone
Xenox Posted November 30, 2016 Author Posted November 30, 2016 JustSomeone, I have tried your solution, still no go. Do I need to configure something in Firefox or somewhere else ? Why I do not see other people encountered this problem ? *Sigh By the way, I have realized that each time after I run the selenium code (the AutoIT exe file not triggering), I am not able to delete the exe file (it seems like still running at background). I think I have to proceed with the other method (insert http://username:password@url in selenium code) which I am not prefer to... *Sigh
JustSomeone Posted November 30, 2016 Posted November 30, 2016 (edited) Your autoit script is most likely still working (not exited or waiting for something) and you cannot delete it. Use this code as autoit code, change your username & password fields, and if needed adjust the Sleep(500). What this code do - upon launching, tries 20 times to locate the auth window of firefox. If the window is not found - it exits with 1, if it's found - exit with 0. If your page is slow loading one - you should delay launching of the Autoit exe with enough time so your page can load. If you get an UAC prompt, remove the first line of the code (#RequireAdmin) or comment it with an ; #RequireAdmin ; unsure if it's needed Opt("WinSearchChildren", 1) $sUsername = "someusername" $sPassword = "somepassword" Sleep(1000) For $i = 1 To 20 Step 1 Sleep(500) $sTitle = WinGetTitle("Authentication Required") If $sTitle = "Authentication Required" Then Send($sUsername & "{TAB}" & $sPassword & "{ENTER}") Exit 0 Else ContinueLoop EndIf Next Exit 1 Edited November 30, 2016 by JustSomeone Edited the code, since it was bit wrong
Xenox Posted December 1, 2016 Author Posted December 1, 2016 JustSomeone, Still no go, I had set the sleep time = 3 sec and waited for 3 minutes, the autoIT code did not run. ***I had also tried with & without "#RequireAdmin" However, this time after waiting for 3 minutes, stopped running my selenium code and closed the browser, re-opened the browser and go to the website manually, the autoIT code no longer trigger. #RequireAdmin Opt("WinSearchChildren", 1) $sUsername = "someusername" $sPassword = "somepassword" Sleep(3000) For $i = 1 To 20 Step 1 Sleep(500) $sTitle = WinGetTitle("Authentication Required") If $sTitle = "Authentication Required" Then Send($sUsername & "{TAB}" & $sPassword & "{ENTER}") Exit 0 Else ContinueLoop EndIf Next Exit 1
Xenox Posted December 1, 2016 Author Posted December 1, 2016 #RequireAdmin Opt("WinSearchChildren", 1) $sUsername = "someusername" $sPassword = "somepassword" Sleep(1000) For $i = 1 To 20 Step 1 Sleep(3000) $sTitle = WinGetTitle("Authentication Required") If $sTitle = "Authentication Required" Then Send($sUsername & "{TAB}" & $sPassword & "{ENTER}") Exit 0 Else ContinueLoop EndIf Next Exit 1 ***pasted the wrong code in the previous reply.
Xenox Posted December 1, 2016 Author Posted December 1, 2016 I have found the solution. Even though I am not sure if it is a valid way, but it really solved my problem. Nothing wrong with the AutoIT code, the problem is in my selenium code. Below is my solution that made in selenium code, I just change the order of autoIT code execution and url navigation. //Run the exe file that compiled from AutoIT to simulate enter username&password into authentication pop up window Runtime.getRuntime().exec("H:\\Automation Script\\Selenium\\SolveAuthPopup.exe"); //Go to OneSpace website (Dev environment) oDriver.get(sWebAppURL); ------------------------------------------------------------------------------------------------------------------------------ Sharing :::: I found out this when I debug my selenium code (the one got problem) again as shown below. When I executed the code, the system did opened up the browser, browsed to the website, the authentication window appeared BUT did not print "test1". So, I just change the order of that 2 code and give it a try. //Go to OneSpace website (Dev environment) oDriver.get(sWebAppURL); System.out.println("test1"); //Run the exe file that compiled from AutoIT to simulate enter username&password into authentication pop up window Runtime.getRuntime().exec("H:\\Automation Script\\Selenium\\SolveAuthPopup.exe"); System.out.println("test2");
JustSomeone Posted December 1, 2016 Posted December 1, 2016 I have no idea on how Selenium etc works, i posted the example above tested with other software. Your problem is that most likely Selenium is pausing itself once it run the firefox driver (therefore waiting for it to quit so it can proceed) AutoIT have similar behaviour, functions are Run and Runwait, most likely this is the issue with selenium too. If you are running the exe before firefox, make sure to give it enough time (or retries) so it does not exit before the firefox page is done loading. In what order you run the firefox driver and the autoit exe it's fully on you and what your program should do. Also a sidenote, storing password inside code is not very secure, there is plenty of people capable of reverting your program.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now