Selectdropdownoptionfromwebbrowser我的目标是我需要选择第二个选项。我已尝试以下操作,但无法设置所选值。如果没有错误,选择就不会发生。我自己对HTML非常熟悉,我知道“selected”和“selected="select"'可以工作,但不确定为什么它不能与我的C#代码一起工作。可能有什么问题?webBrowser1.Document.GetElementById("field_gender1").Children[1].SetAttribute("selected","selected");HTML是val1val2如果在正确的地方,代码应该可以正常工作,例如:button1_Click事件,webBrowser1_DocumentCompleted事件等。ExecutethisoperationfromWebBrowser_DocumentComplete(...)以上是C#学习教程:从webbrowser中选择下拉选项,共享所有内容。如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注—varhtmlDocument=webBrowser1.DocumentasIHTMLDocument2;if(htmlDocument!=null){vardropdown=((IHTMLElement)htmlDocument.all.item("field_gender1"));vardropdownItems=(IHTMLElementCollection)dropdown.children;foreach(下拉项中的IHTMLElement选项){varvalue=option.getAttribute("value").ToString();if(value.Equals("2"))option.setAttribute("selected","selected");}}本文采集自网络,不代表立场,如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
