2 posts, 0 answers
  1. Kiran
    Kiran avatar
    12 posts
    Member since:
    Nov 2010

    Posted 30 Dec 2010 Link to this post


    Here is the scenario where i have to search for an element in the combobox.

    an element - value being a string.

    I am using HtmlSelect control for combobox.
    but htmlSelectControl.Option.Contains( "is accepting an HtmlOption ")

    how do i convert a string to a HtmlOption object??

  2. Stoich
    Stoich avatar
    1 posts

    Posted 05 Jan 2011 Link to this post

    Hello Kiran,
          you can't convert a String to an HtmlOption object. You need to pass an HtmlOption object to the method htmlSelectControl.Option.Contains(). When you pass the object the method checks whether this object  is found in the Collection of the HtmlSelect element.

    You can't use the method since you can't get your hand on an HtmlOption object. You can create one yourself but htmlSelectControl.Option.Contains() will return False for that object because it won't be among the collection of the HtmlSelect.

    Instead let me suggest a different approach to achieve what you want:
    System.Collections.ObjectModel.ReadOnlyCollection<HtmlOption> options
                          = MyHtmlSelect.Options;
                foreach (HtmlOption item in options)
                    if (item.Text.Contains("StringImLookingFor"))
                        Log.WriteLine("The option was found!");

    Let me know if this solution works for!

    the Telerik team
    Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Back to Top