gpt4 book ai didi

c# - 如何在网络浏览器中选择下拉列表选项

转载 作者:太空宇宙 更新时间:2023-11-03 14:53:38 24 4
gpt4 key购买 nike

我正在从事一个 Web 浏览器自动化项目。这是示例代码;

<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 enter = webBrowser1.Document.GetElementById("ctl00_ctl00_main_Content_cbReceiverCity"); enter.SetAttribute("selectedIndex", "5"); enter.InvokeMember("onchange");

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

最佳答案

替换这个

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

有了这个

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

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

关于c# - 如何在网络浏览器中选择下拉列表选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50654669/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com