Html代码:
<span id="syi-attribute-1277" class="dropdown l-stretchable-fixed native" tabindex="7146">
<input type="hidden" value="" name="attribute[1277]"></input>
<span class="label" style=""></span>
<span class="pointer"></span>
<select class="item-frame" size="1" style="height: 30px; width: 264px;">
<option class="item" value=""></option>
<option class="item" value="7146"></option>
<option class="item" value="7147"></option>
<option class="item" value="7148"></option>
</select>
我想做的是我的表单中的webbrowser控件(使用WinForms)能够选择此下拉选择列表的第三个选项(值为7148)。到目前为止我尝试过的事情:
doc.GetElementById("syi-attribute-1277").Children.GetElementsByName("option")[0].SetAttribute("value", "7148");
^最有意义,但遗憾的是它给了我这个错误:附加信息:&#39; 0&#39;对于&#39; index&#39;无效。 &#39;指数&#39;应介于0和-1之间。
代码:
doc.GetElementById("syi-attribute-1277").SetAttribute("tabindex", "7148");
^什么都没发生。
有任何线索吗?谢谢。 :-)
答案 0 :(得分:0)
GetElementsByName
会查找匹配的name
(或id
)属性,而不是元素名称。
您还尝试在option
上设置值属性,如果要设置值,则需要使用select
:
doc.GetElementById("syi-attribute-1277").GetElementsByTagName("select")[0].SetAttribute("value", "7148");