【发布时间】:2018-07-27 11:21:12
【问题描述】:
我正在使用 Windows 窗体应用程序和 webbrowser 控件,并希望让我的代码在网站下拉列表中选择某个值。我已经检查了网站上的元素(见下文):
<div class= "selectize-control">
<div class="selectize-dropdown">
<div class = "selectize-dropdown-content">
<div data-value ="1" data-selectable class ="option">Option1 </div>
<div data-value ="2" data-selectable class ="option"> Option2 </div>
<div data-value ="2" data-selectable class ="option"> Option3 </div>
</div>
</div>
</div>
<span style="display: none;" class= "ValidationMessage" id="ValidationMessage_1"></span>
我想我可以通过编写以下代码来选择“Option2”:
HtmlElementCollection theElementCollection = webBrowser1.Document.All;
foreach (HtmlElement curElement in theElementCollection) {
if (curElement.GetAttribute("className") == "selectize-dropdown-content") {
curElement.SetAttribute("value", "2");
}
}
但是什么都没有发生……谁能帮帮我吗?
【问题讨论】:
标签: c# html css xpath webbrowser-control