Wednesday, December 2, 2009

AutoIT: Mimic User Activities with Files

There was a need for us to perform some user activities while our servioces were running on a system. The activities would be pertaining to file and as below:
1. Opening an instance of excel, winword or wordpad.
2. Writing some text in the opened instance.
3. Saving the file with a filename on the C:\


Script:

Here's the AutoIT script that would perform the above mentioned operations in an excel sheet.

; Run Excel
Run("C:\Program Files\Microsoft Office\Office12\Excel.exe")

WinWaitActive("Microsoft Excel - Book1")
sleep(500)
Send("{F2}")
sleep(500)
;writing into excel
$i = 0
Do
Send("=rand()")
Send("{ENTER}")
$i = $i + 1
Until $i = 500

; Finished!

;saving the document
Send("!f")
sleep(500)
Send("a")
WinWaitActive("Save As")
sleep(500)
Send("C:\Excel")
Send("{ENTER}")
sleep(1000)
Send("!{F4}")



No comments: