Jump to content

Issue with Autoit Script


Recommended Posts

Leave the WinWait command without a timeout and it will wait until the window appears. I have found this to be good practise as it allows for slow machines / networks. This will take care of your reboot.

I like to use AutoIt Window information (Ctrl + F6 in SciTE editor) and add window text because it makes it easier to read in the editor and also can prevent errors if an installer opens many windows with the same name.

I can't think of a reason why the script fails if you remove the MsgBox(s), but you might want to try extending or removing the timeout of each WinWait command.

I have a few questions:

What happens if you remove Window Exists 2?

What are you doing with the ConsoleWrite info?

Do you really need the If / Then after the first two WinWait commands (WinWait without timeout should pause the script until the window appears)?

Why do you want the script to terminate if the expected windows don't open within 5 seconds?

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
Share on other sites

I have a few questions:

What happens if you remove Window Exists 2?

What are you doing with the ConsoleWrite info?

Do you really need the If / Then after the first two WinWait commands (WinWait without timeout should pause the script until the window appears)?

Why do you want the script to terminate if the expected windows don't open within 5 seconds?

Whatever suggestions i received thru FORUM I have used command lines so you may find it mix of different functions.

I will check the points mentioned above and will answer these queries.

I remember first window wasnt appearing without If/then and then I copy pasted it for next dailogues as well.

I will refine my script & share with you on Monday.

Thank you.

Happy Weekend.

Link to comment
Share on other sites

Leave the WinWait command without a timeout and it will wait until the window appears.

Without giving time,it exit...installation of app takes some 5-7 minutes but it exits immediately.

I tried with only

Title

Title & text

Titel Text & timer

Right now I am using third option with giving timeout(approximtae) which is not right but its working.

Please suggest your thoughts.

Link to comment
Share on other sites

At line 41 you have an If / Then Exit. Should this be after the WinWait line?

It depends on what happens at Line 40 (Send("!n")) executes. If the 'Setup Preferences' window disappears, then the script will end. Try commenting it out.

$hWindow = WinWait("UPS WorldShip", "Setup Preferences", 5)
   If Not $hWindow Then Exit
  MsgBox(0, "Window Exists4", "Window found")
$hWindow = WinActivate($hWindow)
Send("{TAB}")
Send("C:\Program Files\UPS\WSTD")
Send("{TAB 2}")
Send("{SPACE}")
Send("{DOWN 4}")
  Send("{TAB}")
  Send("{-}")
Send("!n")
Send("!n")
If Not $hWindow Then Exit  ; Comment this line out!
WinWait("UPS WorldShip")
   WinActivate("UPS WorldShip")
    Send("{ENTER}")
[Autoit]

Try this

[Autoit]

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
Share on other sites

[/size][/size]
[size=3][size=3]$hWindow = WinWait("UPS WorldShip", "Setup Preferences", 6)[/size][/size]
[size=3][size=3]   If Not $hWindow Then Exit[/size][/size]
[size=3][size=3]$hWindow = WinActivate($hWindow)[/size][/size]
[size=3][size=3]Send("{TAB}")[/size][/size]
[size=3][size=3]Send("C:\Program Files\UPS\WSTD")[/size][/size]
[size=3][size=3]Send("{TAB 2}")[/size][/size]
[size=3][size=3]Send("{SPACE}")[/size][/size]
[size=3][size=3]Send("{DOWN 4}")[/size][/size]
[size=3][size=3]  Send("{TAB}")[/size][/size]
[size=3][size=3]Send("{SPACE}")[/size][/size]
[size=3][size=3]Send("!n")[/size][/size]
[size=3][size=3]Send("!n")[/size][/size]
[size=3][size=3]WinWait("UPS WorldShip")[/size][/size]
[size=3][size=3]   WinActivate("UPS WorldShip")[/size][/size]
[size=3][size=3]    Send("{ENTER}")[/size][/size]
[size=3][size=3]Sleep(720000)[/size][/size]
[size=3][size=3]$hWindow = WinWait("UPS WorldShip", "WorldShip Installation Complete", 12)[/size][/size]
[size=3][size=3]$hWindow = WinActivate($hWindow)[/size][/size]
[size=3][size=3]Send("{TAB}")[/size][/size]
[size=3][size=3]Send("{ENTER}")[/size][/size]
[size=3][size=3]

This is the script from second last dialogue.

As the installation takes some 10-12 min I have given sleep time accordingly.

But still when This Installation Complete screen appear it doesn't work.

If in the same script in thirdline from the bottom ,I put msgbox it works great.

If I try running last four lines as saparate script then also it works fine.

But I want this to work in single script..with or without sleep.

Please suggest.

Edited by raviray
Link to comment
Share on other sites

The only thing that the MsgBox will do is pause the script until you click OK, so I suspect the issue is with timing somewhere.

Can you try the following. It is far from perfect (thte Do loop should not be necessary) but it will hopefully give us a pointer as to where the issue is, It is part guesswork as I cannot replicate what you are doing:

Run("Setup.exe")
WinWait("UPS WorldShip")
WinActivate("UPS WorldShip")
Send("{ENTER}")
WinWait("UPS WorldShip")
WinActivate("UPS WorldShip")
Send("{ENTER}")
WinWait("UPS WorldShip", "")
WinActivate("UPS WorldShip")
Send("{ENTER}")
ConsoleWrite("WinActivate activated window: " & ($hWindow <> 0) & @LF)
WinWait("UPS WorldShip", "Please select desired installation type")
WinActivate("UPS WorldShip")
Send("{TAB}")
Send("{SPACE}")
Send("!n")
WinWait("UPS WorldShip", "Setup Preferences")
WinActivate("UPS WorldShip")
Send("{TAB}")
Send("C:\Program Files\UPS\WSTD")
Send("{TAB 2}")
Send("{SPACE}")
Send("{DOWN 4}")
Send("{TAB}")
Send("{-}")
Send("!n")
Send("!n")
WinWait("UPS WorldShip")
WinActivate("UPS WorldShip")
Send("{ENTER}")
Do
WinWait("UPS WorldShip", "WorldShip Installation Complete")
Until WinExists("UPS WorldShip")
WinActivate("UPS WorldShip")
Send("{TAB}")
Send("{ENTER}")
Exit

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
Share on other sites

Can you try the following. It is far from perfect (thte Do loop should not be necessary) but it will hopefully give us a pointer as to where the issue is, It is part guesswork as I cannot replicate what you are doing:

This do loop is working just right & solving my issue.

Thank you very much.

Edited by raviray
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...