Sign in to follow this  
Followers 0
HuaAi

Can't go pass WinWaitActive()

11 posts in this topic

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)

 

Share this post


Link to post
Share on other sites



BTW, ToolTip() did report "IE launched successfully." so WinExists() seems to be able to detect the window.

Share this post


Link to post
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)

 

Share this post


Link to post
Share on other sites

Could anyone run this simple script on your setup and see if you got the same problem?

The ToolTip box is at the top left corner in case you couldn't find it.

Share this post


Link to post
Share on other sites

WinWaitActive($hdlIeWindow, "", 5)

Yeah that fixed the problem! Thanks!

Share this post


Link to post
Share on other sites
$oIE = _IECreate("http://www.google.com")
$hIE = _IEPropertyGet($oIE, "hwnd")
WinActivate($hIE)

 

Nice! Didn't even know IE.au3 exists. Do we have a library for Chrome too?

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  
Followers 0