简体   繁体   中英

select combobox item in website using c#

I need to select a combo box item in a website using c#

i open a website using a web browser

my code is

webBrowser1.Navigate("xxxxx.com");
HtmlElementCollection Col2;
Col2 = webBrowser1.Document.GetElementsByTagName("select");
            foreach (HtmlElement ele in Col2)
            {
                if (ele.Id == "country")
                {
                   ele.InnerText=("palestine");
                }
            }

where is Palestine is one of the items in the combo box. any help please

webBrowser1.Document.GetElementsByTagName("select").SetAttribute("value", "palestine");

or

webBrowser1.Document
           .GetElementsByTagName("select")
           .Children.GetElementsByName("option")[1] // Get option by index
           .SetAttribute("selected", "selected");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM