Section 7.14. Simple UI Automation


7.14. Simple UI Automation

Use the Windows Script Host object model to emulate physical interaction with an application by sending it keystrokes:

     $wsh = new-object -ComObject "WScript.Shell"     $wsh.Run("calc")     start-sleep 1     if ($wsh.AppActivate("Calculator"))     {       "Calc activated"       $keystrokes="1","{+}","2","{+}","3","{=}"       foreach ($key in $keystrokes)       {         start-sleep 1         "Sending $key"         $wsh.SendKeys($key)       }       "Done"     }

The script introduces a small pause between keystrokes to ensure that the application is able to receive and process each in turn. To the application (Calculator, in this case), it appears as though the keystrokes are coming from a real user via the keyboard.




Monad Jumpstart
Monad Jumpstart
ISBN: N/A
EAN: N/A
Year: 2005
Pages: 117

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net