【问题标题】:How to selected drowndown list options in web browser如何在 Web 浏览器中选择下拉列表选项
【发布时间】:2018-06-02 07:46:08
【问题描述】:

我正在做一个网络浏览器自动化项目。 这是示例代码;

<select name="ctl00$ctl00$main$Content$cbReceiverCity" id="ctl00_ctl00_main_Content_cbReceiverCity" tabindex="40" class="custom-select" onchange="javascript:GetTowns(this);void(0);" style="width:170px;" size="5">
    <option selected="selected" value="-1">-- choose one --</option>
    <option value="1">Portugal</option>
    <option value="2">Spain</option>
    <option value="3">France</option>
    <option value="4">Germany</option>
    <option value="5">Italy</option>
</select>

还有我的 c# 代码;

HtmlElement 输入 = webBrowser1.Document.GetElementById("ctl00_ctl00_main_Content_cbReceiverCity"); enter.SetAttribute("selectedIndex", "5"); enter.InvokeMember("onchange");

但是,索引值不会改变。我该如何更改?

【问题讨论】:

    标签: c#


    【解决方案1】:

    替换这个

    enter.SetAttribute("selectedIndex", "5");
    

    有了这个

    enter.Children[5].SetAttribute("selected", "selected");
    

    其中 5 是您要选择的选项的索引

    【讨论】:

      猜你喜欢
      • 2012-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-23
      相关资源
      最近更新 更多