SetEditText parameter findCriteria

Nov 9, 2012 at 7:03 PM

I am trying to use this method to set the text of a drop down list box selected option.

I can find the control but I cannot seem to set it's text value.  I did not find a good example for using the SetEditText extension method with object findCriteria parameter.

public static void SetEditText(this UITestControl container, object findCriteria, string text)

What exactly do I pass in here for the findCriteria param?

I have writen a method that is correctly returning the control.

        public UITestControl DdlAllFindItem(string text)
        {
            var ddlChild = Browser
                .Find(new { Id = "ddlAllItems" })
                .GetChildren().Where(x => x.GetInnerText() == text).FirstOrDefault();

            return ddlChild;
        }


   THX

 

Nov 13, 2012 at 8:55 PM

A little more information on this.  The actual Select - option, the one with the Id above is hidden.  There is an input type control that does not have an Id.  What I want to do is type in the input control which is being used as an autocomplete filter for all the options in the Select control.  I did set, in the javascript the Id of the input and then was able to SetEditText with that Id.  But I really don't want to do this because what if we decide to use this same type of autocomplete on the same page then I will have two different controls with the same Id - not good.  Is there anyway to grab the control based on class information?  Right now it has multiple class items in it but I was thinking that if there were one that did nothing other than identify it I could use that.

Coordinator
Nov 16, 2012 at 9:46 AM

If your drop down is a combobox then the SelectedItem property on the HtmlComboBox should work.

Browser.Find<HtmlComboBox>("mycombo").SelectedItem = "item1";

 

But I've seen situations where this doesn't work for some, yet unknown, reason. The work around could be to first click on the combo and then use SendKeys to set the value

Browser.Find<HtmlComboBox>("mycombo").Click();
Keyboard.SendKeys("item1{ENTER}");

 

hope that helps