Jump to content

Can't go pass WinWaitActive()


Recommended Posts

I basically just want to run IE, go to google, and activate the IE, but couldn't get it working with the script below. The ToolTip() shows that "IE is open!" and we got the handle of the IE window, but the script was never able to execute the last ToolTip() to show the window is activated.

Is there anything I did obviously wrong? I can't find it. Any suggestions? Appreciated!

 

 

run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new http://www.google.com","")
ToolTip("Launching IE...", 0, 0)
sleep(5000)

AutoItSetOption("WinTitleMatchMode", 1)
Local $titleIeWindow = "Google "

If WinExists($titleIeWindow) Then
   ToolTip("IE launched successfully.", 0, 0)
Else
   ToolTip("Can't find IE, leave it for WinWaitActive() to wait")
EndIf
sleep(1000)

Global $hdlIeWindow = WinWait($titleIeWindow)
ToolTip("IE is open!" & " hWnd = " & $hdlIeWindow, 0, 0)

WinActivate($hdlIeWindow)
sleep(1000)
WinWaitActive($hdlIeWindow, 5)

ToolTip("IE is activated!", 0, 0)

 

Link to comment
Share on other sites

Added an extra check after winActivate() and reran it again, ToolTip() reported "WinExists() can detect IE window through $hdlIeWindow too." It confirms that somehow the script gets stuck at WinWaitActive($hdlIeWindow, 5). 

I am on Win 7 Home Premium, SP1, 64-bit. IE 11. the latest AutoIt version, just downloaded.

 

run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new http://www.google.com","")
ToolTip("Launching IE...", 0, 0)
sleep(3000)

AutoItSetOption("WinTitleMatchMode", 1)
Local $titleIeWindow = "Google "

If WinExists($titleIeWindow) Then
   ToolTip("IE launched successfully.", 0, 0)
Else
   ToolTip("Can't find IE, leave it for WinWaitActive() to wait")
EndIf
sleep(1000)

Global $hdlIeWindow = WinWait($titleIeWindow)
ToolTip("IE is open!" & " hWnd = " & $hdlIeWindow, 0, 0)

WinActivate($hdlIeWindow)

If WinExists($hdlIeWindow) Then
   ToolTip("WinExists() can detect IE window through $hdlIeWindow too.", 0, 0)
Else
   ToolTip("Can't find IE, leave it for WinWaitActive() to wait")
EndIf
sleep(1000)

WinWaitActive($hdlIeWindow, 5)

ToolTip("IE is activated!", 0, 0)

 

Link to comment
Share on other sites

After JohnOne pointed out the problem with how I use WinWaitActive(), I fixed my script (test1.au3 in the attachment) and tried to move the window to show I indeed can control the window through its handle. Then I found the script sometimes works and sometimes doesn't. So I added a WinActive() check in the code as below and found sometimes "IE is not activated!" for some reason.

If I use jguinch's method to launch and activate IE window, as in the attached test2.au3, then it works every single time!

Any idea why test1.au3 is flaky?

 

run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new http://www.google.com","")
ToolTip("Launching IE...", 0, 0)

AutoItSetOption("WinTitleMatchMode", 1)
Local $titleIeWindow = "Google "

Global $hdlIeWindow = WinWait($titleIeWindow)
ToolTip("IE is open!" & " hWnd = " & $hdlIeWindow, 0, 0)
sleep(1000)

WinActivate($hdlIeWindow)
Sleep(2000)

If WinActive($hdlIeWindow) Then
   ToolTip("IE is activated!", 0, 0)
Else
   ToolTip("IE is not activated!", 0, 0)
   Sleep(2000)
   WinActivate($hdlIeWindow)
   Exit
EndIf
sleep(1000)

 

test2.au3

test1.au3

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...