WebBrowser control HTMLDocument automate selecting option drop-down

后端 未结 7 2056
栀梦
栀梦 2021-02-02 00:33

I\'m trying to automate in a WinForm using a WebBrowser control to navigate and pull report info from a website. You can enter values in textboxes and invoke the click events fo

7条回答
  •  既然无缘
    2021-02-02 00:55

    var select = webBrowser.Document.GetElementById("ddlProyectos");
    
    mshtml.HTMLSelectElement cbProyectos = select.DomElement as mshtml.HTMLSelectElement;
    
    var total = cbProyectos.length;
    for (var i= 0; i < total; i++)
    {
        cbProyectos.selectedIndex = i;
        if (cbProyectos.value.Contains("13963"))
        {
            break;
        }
    
    }
    //cbProyectos.selectedIndex = 4;
    select.InvokeMember("onchange");
    
    select.Children[4].SetAttribute("selected", "selected");
    
    var theElementCollection = webBrowser.Document.GetElementsByTagName("select");
    foreach (HtmlElement el in theElementCollection)
    {
        if (el.GetAttribute("value").Equals("13963"))
        {
            el.SetAttribute("selected", "selected");
            //el.InvokeMember("click");
        }
    }
    

提交回复
热议问题