C# Webbrowser - 无法通过 ID 获取元素
C# Webbrowser - Can't get element by ID
我在 Webbrowser 控制器中使用 GetElementby Id 时无法检索元素;
网页代码为:
<tr class="tb_item02" align="left">
<td width="15%" class="tb_title" align="right">Set as :</td>
<td width="35%">
<select id="set_AS" name="set_AS" class="select">
<option value=""></option>
<option value="Yes">Yes</option>
<option value="No" selected="">No</option>
</select>
</td>
<td width="15%" class="tb_title" align="right">Re-Generate:</td>
<td width="35%">
<select id=" Regenerate" name="Regenerate" class="select">
<option value=""></option>
<option value="Yes">Yes</option>
<option value="No" selected="">No</option>
</select>
</td>
</tr>
当我尝试通过以下方式获取 set_AS
元素时:
HtmlElement reportDropDown = wbrsr.Document.GetElementById("set_AS");
HtmlElementCollection elCol = reportDropDown.GetElementsByTagName("option");
reportDropDown
保持 null
并且 elcol
正在抛出:
Object reference not set to an instance of an object.
有什么建议我在这里遗漏了什么吗?
已解决:)
纳斯
HtmlElement reportDropDown = wbrsr.Document.GetElementById("set_AS");
HtmlElementCollection elCol = reportDropDown.GetElementsByTagName("option");
在尝试片段中,
在 catch 事件中,触发了另一个 HtmlElement reportDropDown = wbrsr.Document.GetElementById("set_AS");
HtmlElementCollection elCol = reportDropDown.GetElementsByTagName("option");
我在 Webbrowser 控制器中使用 GetElementby Id 时无法检索元素; 网页代码为:
<tr class="tb_item02" align="left">
<td width="15%" class="tb_title" align="right">Set as :</td>
<td width="35%">
<select id="set_AS" name="set_AS" class="select">
<option value=""></option>
<option value="Yes">Yes</option>
<option value="No" selected="">No</option>
</select>
</td>
<td width="15%" class="tb_title" align="right">Re-Generate:</td>
<td width="35%">
<select id=" Regenerate" name="Regenerate" class="select">
<option value=""></option>
<option value="Yes">Yes</option>
<option value="No" selected="">No</option>
</select>
</td>
</tr>
当我尝试通过以下方式获取 set_AS
元素时:
HtmlElement reportDropDown = wbrsr.Document.GetElementById("set_AS");
HtmlElementCollection elCol = reportDropDown.GetElementsByTagName("option");
reportDropDown
保持 null
并且 elcol
正在抛出:
Object reference not set to an instance of an object.
有什么建议我在这里遗漏了什么吗?
已解决:)
纳斯
HtmlElement reportDropDown = wbrsr.Document.GetElementById("set_AS");
HtmlElementCollection elCol = reportDropDown.GetElementsByTagName("option");
在尝试片段中, 在 catch 事件中,触发了另一个 HtmlElement reportDropDown = wbrsr.Document.GetElementById("set_AS"); HtmlElementCollection elCol = reportDropDown.GetElementsByTagName("option");