Is there any Solution for my code problem in webbrowser to identify between Select tag and option

70 views Asked by At

I'm trying to Code webbrowser control to set information to an survey but I face problem to get the Address Survey ?

This is my sample in html Code:

    <label class="control-label required" for="select-address">Your Survey 
    Address is:</label>
     <select name="selectAddress" class="form-control" id="select-address" 
    data-SurveyValidation="true">
    <option selected="selected" disabled="" value="">Select from your 
    Registery:</option>
    <option id="survayAddress_8994716188695" value="8994716188695">
     PO Box A,&nbsp;Andover&nbsp;NY&nbsp;14806,&nbsp;United States
    </option>
    </select>

I tried this but not working!

                HtmlElementCollection col = Browser.Document.GetElementsByTagName("select");
                foreach (HtmlElement heItem in col)
                {

                    if (heItem.GetAttribute("name").Contains("selectAddress") == true)
                    {
                        heItem.SetAttribute("selectedIndex", "8994716188695"); // select value at #3
                        break; // incase of needed... 
                    }
                }

and this one !

    SetComboItem("survayAddress_8994716188695", "8994716188695");
    public void SetComboItem(string id, string value)
    {
        HtmlElement ee = this.Browser.Document.GetElementById(id);
        foreach (HtmlElement item in ee.Children)
        {
            if (item.OuterHtml.ToLower().IndexOf(value.ToLower()) >= 0)
            {
                item.SetAttribute("selected", "selected");
                item.InvokeMember("onChange");
            }
            else
            {
                item.SetAttribute("selected", "");
            }
        }

        ee = this.Browser.Document.GetElementById(id + "-input");
        ee.InnerText = value;
    }
0

There are 0 answers