OWASP O2 Platform Blog

IE Automation: Manipulating RadioButtons

I recently had a query from an O2 user about how to use O2’s IE automation APIs to manipulate radio buttons. Although this could be done by accessing the WatiN IE object directly, that was no O2 Wrapper like the one that exists for other IE objects (buttons, fields, etc..)

I just added a number of RadioButton extension methods to WatiN_ExtensionMethods.cs (which will be synced next time you start O2), and here here is a script that shows how to use it:

panel.clear();

var ie = panel.add_IE().silent(true);

var sampleHtml = "<html>".line()+
"    <head>".line()+
"        <title>My Page</title>".line()+
"    </head>".line()+
"    <body>".line()+
"        <form name=\"myform\" action=\"#\" method=\"POST\">".line()+
"            <input type=\"text\" name=\"textBox1\" value=\"this is a textBox\"><br>".line()+
"            <hr>".line()+
"            <input type=\"radio\" name=\"group1\" value=\"aaa\">Milk<br>".line()+
"            <input type=\"radio\" name=\"group1\" checked>Butter<br>".line()+
"            <input type=\"radio\" name=\"group1\">Cheese".line()+
"            <hr>".line()+
"            <input type=\"radio\" name=\"group2\">Water<br>".line()+
"            <input type=\"radio\" name=\"group2\">Beer<br>".line()+
"            <input type=\"radio\" name=\"group2\"  checked> Wine<br>".line()+
"        </form>".line()+
"    </body>".line()+
"</html>".line();

ie.set_Html(sampleHtml);
//return ie.radioButtons();            // get all radio buttons
//return ie.radioButtons()[0];        // get first radiobutton
//return ie.radioButtons().withName("group1");   // gets the radio buttons with a specific name
//return ie.radioButtons().values();  // get all values
//return ie.radioButtons().withName("group1").values();   // gets values from group
//return ie.radioButtons().names();                           // gets unique names
//return ie.radioButtons().withName("group1").withValue("Cheese");   // gets specific textbox
//return ie.radioButtons().withName("group1").withValue("Cheese").@checked();   // gets checked status
//return ie.radioButtons().withName("group1").withValue("Butter").@checked();
//return ie.radioButtons().withName("group1").withValue("Milk").@checked(true); //set checked status
ie.radioButtons().withName("group1").withValue("Cheese").@checked(true); //set checked status
ie.radioButtons().withName("group2").withValue("Water").@checked(true); //set checked status
return ie.radioButtons();

//O2File:WatiN_IE_ExtensionMethods.cs
//using O2.XRules.Database.Utils.O2
//O2Ref:WatiN.Core.1x.dll

March 31, 2011 - Posted by | IE Automation, WatiN

1 Comment »

  1. […] O2 Script: Manipulating RadioButtons […]

    Pingback by Script to fetch and present large number of Wordpress.com blog entries « O2Platform.com for Developers | April 16, 2011 | Reply


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: