Jump to content

Recommended Posts

Posted

Hi Forum,

I do have a very important question to ask the Forum.

In the examples that I have seen up to now and played with, the application that I will control is started as the first thing in the script. That makes sense of cause, but not necessarily in all cases.

The application that I'm asked to do automation on, is a big package sitting on a server in a big network. During startup, there is a memory management software being loaded and a login dialog to deal with. All in all, it nearly takes 40 sec. before the app shows up. So this big delay doesn't really invite you to start it over and over again to get your little script running.

So, I'm wondering if it's possible somehow to have the big application running and then start the script when the user want's to run his automated procedure doing this, that and whatever.

I have tried it on a simple Notepad example, but it's not working. It's probably missing a handle to the application, to get it all right!

Thanks for any ideas :)

Thanks, Henrik

Posted

Show me somthing that is not working so I will try to help you. Not alone I’m sure. 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Posted
1 hour ago, caramen said:

Show me somthing that is not working so I will try to help you. Not alone I’m sure. 

Hi Caramen,

Here is the script that works fine, when it starts Notepad as the first thing:

; open Notepad
;Run ( "Notepad.exe" )

; wait for Notepad window to exist
Local $hNotepad = WinWait ( "[CLASS:Notepad; TITLE:Unavngivet - Notesblok;]" )

; write "HelloWorld"
ControlSetText ( $hNotepad, "", "[CLASS:Edit; INSTANCE:1]", "HelloWorld" )

; open the SaveAs window (by pressing ALT+f and a)
ControlSend ( $hNotepad, "", "", "{ALT}fg" )

; wait for Save As window to exist
Local $hSaveAs = WinWait ( "[CLASS:#32770; TITLE:Gem som;]" )

; complete the File Name field with "HelloWorld.txt"
ControlSetText ( $hSaveAs, "", "[CLASS:Edit; INSTANCE:1]", "C:\$HemConsult\AUTOIT\HelloWorld.txt" )

; press the Save button
ControlClick ( $hSaveAs, "", "[CLASS:Button; INSTANCE:2]" )

; wait for Bekræft Gem som window to exist
Local $hConfirmSaveAs = WinWait ( "[CLASS:#32770; TITLE:Bekræft Gem som;]", "", 5 )
If $hConfirmSaveAs Then
 ; press the no button
 ControlClick ( $hConfirmSaveAs, "", "[CLASS:Button; INSTANCE:2]" )
 ; press the Cancel button
 ControlClick ( $hSaveAs, "", "[CLASS:Button; INSTANCE:3]" )

EndIf

; wait for Save As window to close
WinWaitClose ( $hSaveAs, "" )

; close the Notepad window
WinClose ( $hNotepad, "" )

; wait for Notepad window to close
WinWaitClose ( $hNotepad, "" )

 

image.png.bb11742e0cb80892d8afd0edc9ee8084.png

This is how far it gets….

Thanks, Henrik

Posted

If Notepad (here an English version) is already open when you run the script, make Notepad active for ALT+fa to work.

There are also a few wrong instance numbers.

; open Notepad
;Run( "Notepad.exe" )

; wait for Notepad window to exist
Local $hNotepad = WinWait( "[CLASS:Notepad; TITLE:Untitled - Notepad;]" )

; write "HelloWorld"
ControlSetText( $hNotepad, "", "[CLASS:Edit; INSTANCE:1]", "HelloWorld" )

; activate Notepad
WinActivate( $hNotepad ) ; <<<<<<<<<<<<<<<<<<<

; open the SaveAs window(by pressing ALT+f and a)
ControlSend( $hNotepad, "", "", "{ALT}fa" )

; wait for Save As window to exist
Local $hSaveAs = WinWait( "[CLASS:#32770; TITLE:Save As;]" )

; complete the File Name field with "HelloWorld.txt"
ControlSetText( $hSaveAs, "", "[CLASS:Edit; INSTANCE:1]", "C:\Windows\Temp\AutoIt\HelloWorld.txt" )

; press the Save button
ControlClick( $hSaveAs, "", "[CLASS:Button; INSTANCE:1]" ) ; 2 --> 1 <<<<<<<<<<<<<<<<<<<

; wait for Bekræft Gem som window to exist
Local $hConfirmSaveAs = WinWait( "[CLASS:#32770; TITLE:Confirm Save As;]", "", 5 )
;Local $hConfirmSaveAs = WinWait( "[CLASS:#32770; TITLE:Confirm Save As;]" )
;ConsoleWrite( "$hConfirmSaveAs = " & $hConfirmSaveAs & @CRLF )
 If $hConfirmSaveAs Then
  ; press the no button
  ControlClick( $hConfirmSaveAs, "", "[CLASS:Button; INSTANCE:2]" )
  ; press the Cancel button
  ControlClick( $hSaveAs, "", "[CLASS:Button; INSTANCE:2]" ) ; 3 --> 2 <<<<<<<<<<<<<<<<<<<
EndIf 

; wait for Save As window to close
WinWaitClose( $hSaveAs, "" )

; close the Notepad window
WinClose( $hNotepad, "" )

; wait for Notepad window to close
WinWaitClose( $hNotepad, "" )

Procedure to test the code: Open an empty Notepad. Run the code in SciTE with F5.

Posted
2 hours ago, LarsJ said:

If Notepad (here an English version) is already open when you run the script, make Notepad active for ALT+fa to work.

There are also a few wrong instance numbers.

; open Notepad
;Run( "Notepad.exe" )

; wait for Notepad window to exist
Local $hNotepad = WinWait( "[CLASS:Notepad; TITLE:Untitled - Notepad;]" )

; write "HelloWorld"
ControlSetText( $hNotepad, "", "[CLASS:Edit; INSTANCE:1]", "HelloWorld" )

; activate Notepad
WinActivate( $hNotepad ) ; <<<<<<<<<<<<<<<<<<<

; open the SaveAs window(by pressing ALT+f and a)
ControlSend( $hNotepad, "", "", "{ALT}fa" )

; wait for Save As window to exist
Local $hSaveAs = WinWait( "[CLASS:#32770; TITLE:Save As;]" )

; complete the File Name field with "HelloWorld.txt"
ControlSetText( $hSaveAs, "", "[CLASS:Edit; INSTANCE:1]", "C:\Windows\Temp\AutoIt\HelloWorld.txt" )

; press the Save button
ControlClick( $hSaveAs, "", "[CLASS:Button; INSTANCE:1]" ) ; 2 --> 1 <<<<<<<<<<<<<<<<<<<

; wait for Bekræft Gem som window to exist
Local $hConfirmSaveAs = WinWait( "[CLASS:#32770; TITLE:Confirm Save As;]", "", 5 )
;Local $hConfirmSaveAs = WinWait( "[CLASS:#32770; TITLE:Confirm Save As;]" )
;ConsoleWrite( "$hConfirmSaveAs = " & $hConfirmSaveAs & @CRLF )
 If $hConfirmSaveAs Then
  ; press the no button
  ControlClick( $hConfirmSaveAs, "", "[CLASS:Button; INSTANCE:2]" )
  ; press the Cancel button
  ControlClick( $hSaveAs, "", "[CLASS:Button; INSTANCE:2]" ) ; 3 --> 2 <<<<<<<<<<<<<<<<<<<
EndIf 

; wait for Save As window to close
WinWaitClose( $hSaveAs, "" )

; close the Notepad window
WinClose( $hNotepad, "" )

; wait for Notepad window to close
WinWaitClose( $hNotepad, "" )

Procedure to test the code: Open an empty Notepad. Run the code in SciTE with F5.

Hi LarsJ,

Thanks. The WinActivate did the trick. 

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
  • Recently Browsing   0 members

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