OWASP O2 Platform Blog

Simple Windows UIAutomation example

Here is a Windows UIAutomation example.

The script below will:

  • open up a new windows form (as a popup window),
  • add a textbox and button to it,
  • set an event handler on the button so that when it is clicked the text of the textbox will change
  • using O2’s API_GuiAutomation to get a reference to the window that was opened (which is running in the current process)
  • move the mouse to the button and click it
  • wait 2 seconds and close the popup window
var windowTitle = "UIAutomationTest - {0}".format(5.randomLetters());
var popupWindow = windowTitle.popupWindow();
var buttonText = "This is a button";
popupWindow.add_TextArea("this is some text inside this textbox")
           .onClick(()=> popupWindow.control<TextBox>(true).set_Text("the button was clicked")); 
var currentProcess = Processes.getCurrentProcess();
var guiAutomation = new API_GuiAutomation(currentProcess);
var window  =  guiAutomation.window(windowTitle);
if (window.notNull())
    "got reference to window".info();
//    window.mouse();
    var button = window.button(buttonText);
    if (button.notNull())
        "got reference to button".info();
    "could not get window ref".error();


return "ok";


June 18, 2011 - Posted by | Interoperability

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: