Home > Others > RadCombobox & WATIN

RadCombobox & WATIN

Recently we ran into the problem of selecting an item from a RadCombobox using WATIN. I had shared Ayende’s blog post which pointed to the execScript API earlier with my team. For some reason I didn’t pursue it further on the possibilities of using execScript to select an Item in RadCombobox. Today I thought of giving it a try after seeing the response from Telerik support & Elena Tosheva’s blog entry. I do not like the idea of fiddling with the RadCombobox rendering internals. Telerik does provide a client side object model to manipulate a RadCombobox. I decided to use that in combination with execScript to select an Item in the RadCombobox. Here is the code snippet.

        public static void SelectItemByValue(IE ie, string dropDownName, string valueToSelect)
{
string javascript = string.Format(@"
var dropDownClientObject = $find('{0}');
if(dropDownClientObject)
{{
var itemToSelect = dropDownClientObject.findItemByValue('{1}');
if(itemToSelect)
{{
itemToSelect.select();
}}
else
{{
alert('Unable to find Item with value {1}');
}}
}}
else
{{
alert('Unable to find DropDown with ID {0}');
}}
", dropDownName, valueToSelect);
ie.HtmlDocument.parentWindow.execScript(javascript, "javascript");
}

I am open to inputs on any other better way of doing this. Hope this helps someone who is in need of this

Advertisements
Categories: Others
  1. No comments yet.
  1. No trackbacks 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: