beldeamon Posted October 1, 2020 Posted October 1, 2020 (edited) Good afternoon, i am wondering if anyone has come across this and if they can shed some light, I am running some compiled (see below) that basically uses the webdriver and FF to login to amazon quicksights and download some reports and then format them. My issue is that on the odd occasion (it runs scheduled 5 times a day, so maybe once or twice a week will fail with the below scenario) i have issues setting a window active. I do this to ensure any commands are sent to the correct window before i issue them. The logic works and have seen it take over if i am working on something at the same time. Windows reports back a handle of 0x00000000 for the active window and although i can obtain the handle of my FF window it refuses to be set as the active one. I am not sure if this is a windows issue or a problem getting the handle of what windows perceives is the active window. Thanks for any thoughts And apologies for any of the code ....... i do this out of necessity, not as a profession. Beldeamon MY Logging 2020-10-01 14:05:02.659 --> Calling WD_Startup ... 2020-10-01 14:05:03.487 --> WD Startup - Returncode= 0 Extended= 0 Text=4560 2020-10-01 14:05:08.221 --> WD CreateSession - Return code = 0 Extended= 200 Text=abfd1bcc-7d11-4f9d-a150-6e1a207d13c4 2020-10-01 14:05:11.284 --> WD Navigate Return code = 0 Extended= 200 Text=abfd1bcc-7d11-4f9d-a150-6e1a207d13c4 2020-10-01 14:05:11.315 --> WD Check I am Top Window = 0 Extended= 0 Text=abfd1bcc-7d11-4f9d-a150-6e1a207d13c4 2020-10-01 14:05:12.315 --> Wait for Account Page - Return code = 0 Extended= 0 Text=1 2020-10-01 14:05:12.331 --> Find for Account Page - Return code = 0 Extended= 200 Text=8228f71d-af49-4ca9-8fd5-ce519a77a687 2020-10-01 14:05:12.378 --> Enter for Account Page - Return code = 0 Extended= 200 Text={"value":null} 2020-10-01 14:05:13.377 --> Check for Continue Button - Return code = 0 Extended= 0 Text=1 2020-10-01 14:05:13.393 --> Find for Continue Button - Return code = 0 Extended= 200 Text=dd784964-8402-455d-8a74-c4db5a4d4219 2020-10-01 14:05:13.393 --> Window was not the active one - Current actual has handle of 0x00000000 and title of 2020-10-01 14:05:13.393 --> Trying to set Active : Amazon Web Services Sign-In - Mozilla Firefox 2020-10-01 14:05:13.393 --> Found the following Windows ... 2020-10-01 14:05:13.393 --> 1 - MDA_EXPORT.EXE - taskeng.exe - 0x00D604A2 2020-10-01 14:05:13.393 --> 2 - FIREFOX.EXE - Amazon Web Services Sign-In - Mozilla Firefox - 0x000F0262 2020-10-01 14:05:13.659 --> Failed to Set Active Window - Retrying 2020-10-01 14:05:29.190 --> Failed to Set Active Window - Retrying 2020-10-01 14:05:44.721 --> Failed to Set Active Window - Retrying 2020-10-01 14:06:00.284 --> Failed to Set Active Window - Retrying 2020-10-01 14:06:15.846 --> Failed to Set Active Window - Retrying 2020-10-01 14:06:31.112 --> Failed to Set Active Window - Timedout 2020-10-01 14:06:31.112 --> Found the following Windows ... 2020-10-01 14:06:31.112 --> 1 - FIREFOX.EXE - Amazon Web Services Sign-In - Mozilla Firefox - 0x000F0262 2020-10-01 14:06:31.112 --> 2 - MDA_EXPORT.EXE - taskeng.exe - 0x00D604A2 2020-10-01 14:06:31.112 --> Current Window was reporting as handle of 0x00000000 and title of 2020-10-01 14:06:31.143 --> Exit as unable to set correct windows as active 2020-10-01 14:06:31.143 --> Deleting Webdriver Session 2020-10-01 14:06:34.081 --> Shutting down WebDriver PART CODE .. EXTRACT expandcollapse popupGlobal $winchk1 = "Amazon Web Services Sign-In - Mozilla Firefox" WinMinimizeAll() Start_WebDriver() QuickSights_Login() Func QuickSights_Login() ;If $_WD_DEBUG Then _ ; logwrite($sFuncName & ': ' & $sResponse & @CRLF) $cmd = _WD_Navigate($sSession, $site2) $iResult = @error logwrite("WD Navigate Return code = " & $iResult & " Extended= " & @extended & " Text=" & $sSession & @crlf) $cmd = _WD_IsWindowTop($sSession) $iResult = @error logwrite("WD Check I am Top Window = " & $iResult & " Extended= " & @extended & " Text=" & $sSession & @crlf) $cmd = _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='account']",1000, 120000) $iResult = @error logwrite("Wait for Account Page - Return code = " & $iResult & " Extended= " & @extended & " Text=" & $cmd & @crlf) $sElement_account = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='account']") $iResult = @error logwrite("Find for Account Page - Return code = " & $iResult & " Extended= " & @extended & " Text=" & $sElement_account & @crlf) $cmd = _WD_ElementAction($sSession, $sElement_account, 'value',$qsaccount) $iResult = @error logwrite("Enter for Account Page - Return code = " & $iResult & " Extended= " & @extended & " Text=" & $cmd & @crlf) $cmd = _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//button[contains(text(),'Continue')]",1000,5000) $iResult = @error logwrite("Check for Continue Button - Return code = " & $iResult & " Extended= " & @extended & " Text=" & $cmd & @crlf) $sElement_account = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[contains(text(),'Continue')]") $iResult = @error logwrite("Find for Continue Button - Return code = " & $iResult & " Extended= " & @extended & " Text=" & $sElement_account & @crlf) Mozilla_Active($winchk1) Send("{ENTER}") Sleep(2000) ........ More Code EndFunc Func Mozilla_Active($windowname) local $mywindow = WinGetHandle($windowname) if @error > 0 then ; Strange but true !! Should not happen logwrite("Unable to get handle to window we are checking - " & $windowname & @crlf) Mozilla_Window_Debug() exit 9999 endif local $action = 0 local $sTitle = WinGetTitle("[active]") local $hActive = WinGetHandle("[active]") If WinActive($windowname) Then logwrite("Window is already the active One" & @crlf) Else logwrite("Window was not the active one - Current actual has handle of " & $hActive & " and title of " & $sTitle & @crlf) logwrite("Trying to set Active : " & $windowname & @crlf) Mozilla_Window_Debug() For $j = 1 to 5 If WinActivate($windowname) then logwrite("Window is now the active one" & @crlf) $action = 1 exitloop Else logwrite("Failed to Set Active Window - Retrying" & @crlf) ; Use Winwait active to try for 15 seconds to see if it activates WinMinimizeAll() ; Use Winwait active to try for 15 seconds to see if it activates WinWaitActive($windowname,"",15) EndIf Next if $action = 0 then logwrite("Failed to Set Active Window - Timedout" & @crlf) Mozilla_Window_Debug() errorwrite("Exit as unable to set correct windows as active") endif Endif EndFunc Func Mozilla_Window_Debug() Local $hWindow, $vWinStyle, $aWinNormal[1][3] Local $aWinList = WinList("[REGEXPTITLE:(?i)(.+)]") Local $iPID = 0 For $i = $aWinList[0][0] To 1 Step - 1 If $aWinList[$i][0] = "" Then ContinueLoop $hWindow = WinGetHandle($aWinList[$i][1], "") If Not $hWindow Then ContinueLoop $vWinStyle = _WinAPI_GetWindowLong($hWindow, $GWL_STYLE) If BitAND(WinGetState($aWinList[$i][1]), 4) = 4 _ And BitAND($vWinStyle, $WS_VISIBLE) = $WS_VISIBLE _ And BitAND($vWinStyle, $WS_MINIMIZEBOX) = $WS_MINIMIZEBOX _ And BitAND($vWinStyle, $WS_MAXIMIZEBOX) = $WS_MAXIMIZEBOX Then Local $iThread = _WinAPI_GetWindowThreadProcessId($hWindow, $iPID) _ArrayAdd($aWinNormal, _WinAPI_GetProcessName($iPID) & "|" & $aWinList[$i][0] & "|" & $aWinList[$i][1]) endif Next logwrite("Found the following Windows ..." & @crlf) for $i = 1 to ubound($aWinNormal) -1 logwrite(StringFormat("%3i",$i) & " - " & stringupper($aWinNormal[$i][0]) & " - " & $aWinNormal[$i][1] & " - " & $aWinNormal[$i][2] & @crlf) next EndFunc Edited October 1, 2020 by beldeamon
beldeamon Posted October 1, 2020 Author Posted October 1, 2020 Quick update as i have been trying to get to the bottom of this one ... I now believe the issue is related to a locked/disconnected windows session and issuing of command keys/command to a window, which appears to not be possible.
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