This is a migrated thread and some comments may be shown as answers.

Selecting a value in DDL via WatiN

1 Answer 36 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 15 May 2015, 02:44 PM

I'm trying to select a value in my DDL list via the WatiN browser control debugging tool...

Here is my input item: 

<input id="ProviderList" name="ProviderList" style="width:400px" type="text" /><script>
jQuery(function(){jQuery("#ProviderList").kendoDropDownList({"dataBound":dataBoundProviderList,"dataSource":[{"Key":"001","Value":"001 Provider 1"},{"Key":"002","Value":"002 Provider 2"}],"dataTextField":"Value","dataValueField":"Key"});});
</script>

 

I tried the following without success to preselect the 2nd item in my unit test:

  TextField providerListElement = Browser.TextField(Find.ByName("ProviderList"));

 

//via a jquery script from WatiN:
Browser.Eval("$\"#ProviderList\").data('kendoDropDownList').value(\"002\");");

// or another attempt via WatiN using jquery:
var dropdownlist = $(\"#ProviderList\").data(\"kendoDropDownList\"); dropdownlist.select(function (dataItem) { return dataItem.symbol === \"002\";});");

// and one more try:

Browser.Eval("$(document).ready(function() { " +
                        " var dropdownlist = $(\"#ProviderList\").data(\"kendoDropDownList\"); " +
                        " dropdownlist.select(function (dataItem) { return dataItem.symbol === \"02\"});" +
                        "});  ");

//also tried treating it as text field

providerListElement.Value = "002";

//as text field using simulated typing
providerListElement.TypeText("002");

 

Nothing seems to let the field change.

 Any thoughts would be helpful!

 

Thanks,

Robert

 

1 Answer, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 18 May 2015, 06:51 PM

figured it out. 

Browser.Eval("$(\"#ProviderList\").data(\"kendoDropDownList\").value(\"" + providerValue + "\");");

Tags
DropDownList
Asked by
Robert
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Share this question
or