Jump to content

WinWait, not finding window?


AutoDub
 Share

Go to solution Solved by AutoDub,

Recommended Posts

Hi all,

I'm new to AutoIt and I am trying to build my first script.

The script is meant to open a link in IE, enter text in a field and then download a file, that will automatically run.

^

This part, no problem.

When the file (installation) has finished running, a message box appears, with only one choice - "OK".

What I am trying to do is, have the script wait for the message box using WinWait.

I added a message box after the WinWait, just to see if it actually found the window - but no message box appeared, and the script finished after 98 seconds. (Timeout for the WinWait is 120 seconds...?)

 

Code:

#include <IE.au3>
#include <MsgBoxConstants.au3>
$sHeight = @DesktopHeight
$sWidth = @DesktopWidth
$usernameXXXX = InputBox("Enter your XXX Userid (XXXXX)", "Enter your XXXX Userid (XXXXX)")
$usernameINTRANET = InputBox("Enter your Intranet username (emailaddress)", "Enter your Intranet username (emailaddress)")
$passwordINTRANET = InputBox("Enter your Intranet Password", "Enter your intranet password")
 
 
 
$sURL = "XXXXXXX"
$oIE = _IECreate($sURL, 0, 0, 0)
$HWND = _IEPropertyGet($oIE, "hwnd")
WinSetState($HWND, "", @SW_MAXIMIZE)
_IEAction($oIE, "visible")
_IELoadWait($oIE)
WinMove($HWND, "", 0, 0)
WinActivate($HWND)
 
; Fill text field in IE
    MouseClickDrag("left", ($sWidth * 0.0765625), ($sHeight * 0.4970703125), ($sWidth * 0.0109375), ($sHeight * 0.4970703125))
    Send($usernameXXXX)
    send("{ENTER}")
 
; Wait for window and click enter
        WinWait("Installation complete!","", 120)
        MsgBox($MB_OK, "Test", "Test", 10)
        WinActivate("Installation complete!")
        Send("{ENTER}")

Window information;

Title Installation complete!
Class #32770
Position 510, 790
Size 312, 174
Style 0x94C80347
ExStyle 0x00010108
Handle 0x0016123C

Anyone have any ideas what I am doing wrong here?

Worth noting is that I also tried replacing

WinWait("Installation complete!","", 120)

with

WinWait("[Class:#32770]","", 120)
Edited by AutoDub
Link to comment
Share on other sites

  • Moderators

AutoDub, have a look at Opt in the help file. One of the parameters is WinTitleMatchMode, which you can set to match any portion of the title. Try that option, and shortening your WinWait parameter to something like  "Installation c".

Edit: Also, try to find some text on the window, and enter this as your second WinWait parameter.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

AutoDub, have a look at Opt in the help file. One of the parameters is WinTitleMatchMode, which you can set to match any portion of the title. Try that option, and shortening your WinWait parameter to something like  "Installation c".

Edit: Also, try to find some text on the window, and enter this as your second WinWait parameter.

 

Thank you JLogan3o13, it seems as it is able to detect the window after I changed the code as following;

opt("wintitlematchmode",2)
        WinWait("Installation c","", 120)
        WinActivate("Installation c")
        WinMove("Installation c", "", 0, 0)
        Send("{ENTER}")
        MsgBox($MB_OK, "Test", "Test")

The MsgBox appears (which I added just to make sure that it actually finds the window), but it seems as the functions WinActivate, WinMove and Send does not execute...

Link to comment
Share on other sites

  • Moderators

So, if you WinActivate and then add in a long sleep (2 seconds), you never see the window activate?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

So, if you WinActivate and then add in a long sleep (2 seconds), you never see the window activate?

 

I tried editing my script to the following;

opt("wintitlematchmode",2)
        WinWait("Installation c","", 120)
        WinActivate("Installation c")
        sleep(5000)
        Send("{ENTER}")
        Run("notepad.exe")
        WinWait("Untitled - Notepad")
        Send("WinWait is working")

; click on OK
        MouseClick("left", 744,580) 
        Sleep(2000)

; click on startmenu
        MouseClick("left", 25,1006)
        Sleep(5000)

; click on ok
        MouseClick("left", 744,580)
        Sleep(5000)

When running the script now, it pauses for 5 seconds, with the "Installation complete!" window active, the OK button that the window has - is never pressed.

After the 5 seconds, Notepad opens up and the text is printed out.

After this, the mouse should be clicking in the middle of the OK button, but again it fails to actually interact with the button...

It manages to press the startmenu button, but after the 5 second pause time - it again fails to click the OK button.

Me myself on the other hand, have no issues clicking the button manually.

It seems that is something fishy with the window itself :/

Edited by AutoDub
Link to comment
Share on other sites

  • Moderators

Can you please post the Window Info for this popup? It may be much easier to control through the control commands.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

This is the Window info if i put the finder on the actual OK button of the popup;

>>>> Window <<<<
Title:    Installation complete!
Class:    #32770
Position:    487, 435
Size:    312, 174
Style:    0x94C80347
ExStyle:    0x00010108
Handle:    0x000F1AF2
 
>>>> Control <<<<
Class:    Button
Instance:    1
ClassnameNN:    Button1
Name:    
Advanced (Class):    [CLASS:Button; INSTANCE:1]
ID:    2
Text:    OK
Position:    212, 109
Size:    88, 26
ControlClick Coords:    38, 6
Style:    0x50030000
ExStyle:    0x00000004
Handle:    0x000C1646
 
>>>> Mouse <<<<
Position:    740, 575
Cursor ID:    0
Color:    0xF0F0F0
 
>>>> StatusBar <<<<
 
>>>> ToolsBar <<<<
 
>>>> Visible Text <<<<
OK
Installation of

  "Application name" completed.
 
 
>>>> Hidden Text <<<<
Edited by AutoDub
Link to comment
Share on other sites

Try to stay away from Send, use any of the following:

; Window Automation
ControlClick
ControlSetText

; setting value of an IE element...don't use send, use
_IEFormElementSetValue
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

 

Try to stay away from Send, use any of the following:

; Window Automation

ControlClick

ControlSetText

; setting value of an IE element...don't use send, use

_IEFormElementSetValue

 

 

Thanks, modified my code and I now have the following, much cleaner code;

#include <IE.au3>
 
$usernameXXXX = InputBox("Enter your XXXX Userid (XXXX)", "Enter your XXXX Userid (XXXX)")
$usernameINTRANET = InputBox("Enter your Intranet username (emailaddress)", "Enter your Intranet username (emailaddress)")
$passwordINTRANET = InputBox("Enter your Intranet Password", "Enter your intranet password")
 
 
Local $oIE = _IECreate("MYURL")
Local $oForm = _IEFormGetObjByName($oIE, "formname")
Local $oText = _IEFormElementGetObjByName($oForm, "formlabel")
_IEFormElementSetValue($oText, $usernameXXXX)
Local $oSubmit = _IEGetObjByName($oIE, "submit_button")
_IEAction($oSubmit, "click")
_IELoadWait($oIE)
Sleep(2000)
Send("!O")
 
 
opt("wintitlematchmode",2)
        WinWait("Installation c","", 0)
        WinActivate("Installation c")
        ControlClick("Installation c", "", "Button1")

I am still having troubles with having the script clicking the "OK" button.

The window is a child/sub window and there is only one button in it.

Below is the summary of the window. Am I using the ControlClick incorrectly?

>>>> Window <<<<
Title:    Installation complete!
Class:    #32770
Position:    413, 377
Size:    312, 174
Style:    0x94C80347
ExStyle:    0x00010108
Handle:    0x00060D32
 
>>>> Control <<<<
Class:    Button
Instance:    1
ClassnameNN:    Button1
Name:    
Advanced (Class):    [CLASS:Button; INSTANCE:1]
ID:    2
Text:    OK
Position:    212, 109
Size:    88, 26
ControlClick Coords:    45, 11
Style:    0x50030000
ExStyle:    0x00000004
Handle:    0x00050E0A
 
>>>> Mouse <<<<
Position:    673, 522
Cursor ID:    0
Color:    0xEBEBEB
 
>>>> StatusBar <<<<
 
>>>> ToolsBar <<<<
 
>>>> Visible Text <<<<
OK
Installation of

  Application name completed.
 
 
>>>> Hidden Text <<<<
Edited by AutoDub
Link to comment
Share on other sites

Ok,

So I bypassed the Window that I previously had issues with clicking "OK" on by just killing the process.

However, I am now facing a situation where I cannot do this.

I have a installation that starts, and right when it starts it opens a child window where you need to click "OK" for the installation to continue.

Here is the info from the main window;

>>>> Window <<<<
Title:    Software Installer
Class:    ABCD
Position:    202, 154
Size:    620, 460
Style:    0x1CC50000
ExStyle:    0x00000100
Handle:    0x000804F4
 
>>>> Control <<<<
Class:    
Instance:    
ClassnameNN:    
Name:    
Advanced (Class):    
ID:    
Text:    
Position:    
Size:    
ControlClick Coords:    
Style:    
ExStyle:    
Handle:    
 
>>>> Mouse <<<<
Position:    460, 334
Cursor ID:    0
Color:    0xFFFFFF
 
>>>> StatusBar <<<<
 
>>>> ToolsBar <<<<
 
>>>> Visible Text <<<<
Cancel
 
 
>>>> Hidden Text <<<<
Installation messages:

Here is the info from the child window that has the button I need to press;

>>>> Window <<<<
Title:    Installing my application
Class:    #32770
Position:    189, 241
Size:    477, 204
Style:    0x94C80347
ExStyle:    0x00010108
Handle:    0x00170518
 
>>>> Control <<<<
Class:    Button
Instance:    1
ClassnameNN:    Button1
Name:    
Advanced (Class):    [CLASS:Button; INSTANCE:1]
ID:    2
Text:    OK
Position:    375, 139
Size:    88, 26
ControlClick Coords:    56, 13
Style:    0x50030000
ExStyle:    0x00000004
Handle:    0x0001051C
 
>>>> Mouse <<<<
Position:    623, 418
Cursor ID:    0
Color:    0xDDDDDD
 
>>>> StatusBar <<<<
 
>>>> ToolsBar <<<<
 
>>>> Visible Text <<<<
OK
This is a placeholder
 
 
>>>> Hidden Text <<<<

And here is the code I am trying to use;

opt("wintitlematchmode",2)
Local $nWnd = WinWait("Installing my","This is a placeholder", 0)
ControlClick($nWnd, "", "Button1")

I also tried;

opt("wintitlematchmode",2)
Local $nWnd = WinWait("Installing my","This is a placeholder", 0)
ControlClick("Software Installer", "", "Button1")

None of the above works, but if i add a message box after the ControlClick, the message box appears and the scripts finishes.

 

Edited by AutoDub
Link to comment
Share on other sites

Can anyone see anything wrong in this ControlClick?

opt("wintitlematchmode",2) 
Local $nWnd = WinWait("Installing my","This is a placeholder", 0) 
ControlClick($nWnd, "", "Button1")

I also tried the following

opt("wintitlematchmode",2)
WinWait("Installing my","This is a placeholder", 0)
ControlClick("Installing my", "", "Button1") 

This is the window info

>>>> Window <<<<
Title:    Installing my application
Class:    #32770
Position:    189, 241
Size:    477, 204
Style:    0x94C80347
ExStyle:    0x00010108
Handle:    0x00170518
 
>>>> Control <<<<
Class:    Button
Instance:    1
ClassnameNN:    Button1
Name:    
Advanced (Class):    [CLASS:Button; INSTANCE:1]
ID:    2
Text:    OK
Position:    375, 139
Size:    88, 26
ControlClick Coords:    56, 13
Style:    0x50030000
ExStyle:    0x00000004
Handle:    0x0001051C
 
>>>> Mouse <<<<
Position:    623, 418
Cursor ID:    0
Color:    0xDDDDDD
 
>>>> StatusBar <<<<
 
>>>> ToolsBar <<<<
 
>>>> Visible Text <<<<
OK
This is a placeholder
 
 
>>>> Hidden Text <<<<
Edited by AutoDub
Link to comment
Share on other sites

You probably want a bit of a timeout...then add error handling to see if it succeeds...otherwise, the code looks fine:

Local $nWnd = WinWait("Installing my","This is a placeholder", 10) 
If IsHWnd($nWnd) Then
    MsgBox(1,1,"found window")
Else
    MsgBox(1,1,"NO window found")
EndIf

You are running this interactivly, right?  On your user session?

If not, then the text will be hidden, so you must specify to look for hidden text with

AutoItSetOption
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Are your mouse buttons switched at all?

Try setting the button in ControlClick to "Primary".

 

Buttons are not switched, ControlClick working perfectly in other windows. Tried defining the mouseclick to use the primary button, with no change to the behavior at all.. :/

 

 

You probably want a bit of a timeout...then add error handling to see if it succeeds...otherwise, the code looks fine:

Local $nWnd = WinWait("Installing my","This is a placeholder", 10)

If IsHWnd($nWnd) Then

    MsgBox(1,1,"found window")

Else

    MsgBox(1,1,"NO window found")

EndIf

You are running this interactivly, right?  On your user session?

If not, then the text will be hidden, so you must specify to look for hidden text with

AutoItSetOption

 

 

It is ran form my user session, yes. The window is found, with the error handling I get "found window" as soon as it appears.

Feels like everything has been tried now, not even a "MouseClick" at the coordinates the button is at works.

I think that the window itself must have some irritating special property, I've earlier stated that it is a child window, do I have to interact differently with it because of this? I already tried adding

Opt("WinSearchChildren", 1)
Link to comment
Share on other sites

Is your script running the installer?

Is your script running as admin?

Does your installer require UAC (to run as admin)?

Hopefully these answers are all yes, or your script won't be able to interact with the window.  Keep with the controlclick, not the mouseclick.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Is your script running the installer?

Is your script running as admin?

Does your installer require UAC (to run as admin)?

Hopefully these answers are all yes, or your script won't be able to interact with the window.  Keep with the controlclick, not the mouseclick.

"Is your script running the installer?"

My script downloads the file that is needed to initiate the installation, the installation starts in a custom built software that takes care of the installation itself.

"Is your script running as admin?" Yes.

"Does your installer require UAC?" No, it doesn't. And sadly I was not aware that this was needed. Weird though that it manages to interact with some parts of the installer, but not this particular window..

 

It's about time you give the link to this mysterious application, so people might try it.

 

If I could I would, but it's an application that can only be installed from our internal company network with our companies software installer.

 

Seems as the nature of the installer will prevent me from using autoit... Guess I will give a different language a try :/ Shame since I got so far with what I wanted to do :/

Edited by AutoDub
Link to comment
Share on other sites

I see no reason why you couln't use autoit.

Add the same if statement around every step, and consolewrite the results...you need to see exactly where your script is failing.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...