如何从C#中的HTML页面正确加载组合框对象? 为什么我不能阅读" root"的所有后代。 ?
<select name="mainCategory">
<option value=""> select1 </option>
<option value="21"> Antiques & Art </option>
<option value="61"> Office and Advertising </option>
<option value="22"> Jewelry & Watches </option>
<option value="23"> For Kids </option>
<option value="24"> Home & Garden </option>
<option value="39"> Erotica </option>
<option value="25"> Videos </option>
<option value="26"> Company and Industry </option>
<option value="27"> Photography </option>
<option value="28"> Games </option>
<option value="29"> Collections </option>
<option value="30"> Computers </option>
<option value="31"> Books and Comics </option>
<option value="32"> Automotive </option>
<option value="33"> Music and Instruments </option>
<option value="34"> Clothing, Shoes, Accessories </option>
<option value="40" selected="selected"> Other </option>
<option value="81"> Crafts </option>
<option value="35"> Consumer Electronics </option>
<option value="36"> Sport and Tourism </option>
<option value="37"> Phones & Accessories </option>
<option value="38"> Health and Beauty </option>
<option value="62"> Food </option>
</select>
使用此类代码:
HtmlElement root = this.webBrowser1.Document.GetElementsByTagName("select")[2];
或
HtmlElement root = this.webBrowser1.Document.GetElementById("mainCategory");
元素&#34; root&#34;只包含一个孩子 - &#34; select1&#34;,没有更多的后代。 为什么我不能阅读&#34; root&#34;的所有后代。 ?
答案 0 :(得分:0)
您的OPTION
标签似乎格式不正确。而不是:
<option> value="21"> Antiques & Art </option>
应该是:
<option value="21"> Antiques & Art </option>
第一个是正确创建的。
虽然我相信某些浏览器可能没有渲染它的问题,但我不知道该模型会通过验证。
[编辑]我在您修复帖子上的标签之前发布了这个答案。它现在有效吗?