我需要从webBrowser控件的当前选定选项中选择innerText
。如何从webBrowser控件的当前选定选项中获取innerText
下面是HTML的表示:
<SELECT ID="F8">
<OPTION VALUE="option1">option1</OPTION>
<OPTION VALUE="option2" selected>option2</OPTION>
<OPTION VALUE="option3">option3</OPTION>
</SELECT>
这里就是我想:
if (webBrowser1.Document.GetElementById("F8") != null)
{
HtmlElement selectF8 = webBrowser1.Document.GetElementById("F8");
foreach (HtmlElement item in selectF8.Children)
{
if (item.GetAttribute("selected") != null)
{
assigneeText.Text = item.InnerText;
}
}
}
...但它完全忽略了if语句始终分配assigneeText.Text
的价值option3
而不是所选的option2
的值。
有人能告诉我我做错了什么吗?
谢谢..这个工程!我在下面找到了另一个解决方案,但是这可能比我的解决方案更好... – smitty1