Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过webbrowser控件与选项元素的交互?_C#_Html_Winforms_Webbrowser Control - Fatal编程技术网

C# 通过webbrowser控件与选项元素的交互?

C# 通过webbrowser控件与选项元素的交互?,c#,html,winforms,webbrowser-control,C#,Html,Winforms,Webbrowser Control,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="point

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>
^最有意义,但遗憾的是它给了我这个错误:附加信息:“0”的值对“index”无效索引“”应介于0和-1之间

代码:

^什么也没发生

有线索吗?谢谢

GetElementsByName查找匹配的名称或id属性,而不是元素名称

您还试图在选项上设置value属性,如果要设置值,则需要使用select:

doc.GetElementById("syi-attribute-1277").GetElementsByTagName("select")[0].SetAttribute("value", "7148");

id为syi-attribute-1277的元素在哪里?就在那里!我把这篇文章的格式弄错了。很抱歉你能试试这个吗?getElementsByClassNameoption[0].SetAttributevalue,7148@Eplzong错误1“System.Windows.Forms.HtmlDocument”不包含“getElementsByClassName”的定义,并且找不到接受类型为“System.Windows.Forms.HtmlDocument”的第一个参数的扩展方法“getElementsByClassName”。是否缺少using指令或程序集引用?确定。尝试使用doc.GetElementsByTagNameoption[0]捕获它们;谢谢你的帮助!我尝试了此操作,但仍然收到错误消息:“System.Windows.Forms.dll”中发生了类型为“System.ArgumentOutOfRangeException”的未处理异常。其他信息:“0”的值对“index”无效“索引”应介于0和-1之间。我可以使用-您正在等待文档完全加载?是的,我甚至添加了一个延迟4秒的计时器,以确保文档已完全加载。还是有例外。
doc.GetElementById("syi-attribute-1277").SetAttribute("tabindex", "7148");
doc.GetElementById("syi-attribute-1277").GetElementsByTagName("select")[0].SetAttribute("value", "7148");