Selecting a value in DDL via WatiN

2 posts, 0 answers
  1. Robert
    Robert avatar
    2 posts
    Member since:
    May 2015

    Posted 15 May 2015 Link to this post

    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

     

  2. Robert
    Robert avatar
    2 posts
    Member since:
    May 2015

    Posted 18 May 2015 in reply to Robert Link to this post

    figured it out. 

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

  3. Kendo UI is VS 2017 Ready
Back to Top