Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.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 null元素在从集合到单个变量的赋值中_C#_Webbrowser Control - Fatal编程技术网

C#WebBrowser null元素在从集合到单个变量的赋值中

C#WebBrowser null元素在从集合到单个变量的赋值中,c#,webbrowser-control,C#,Webbrowser Control,我已经和WebBrowser一起导航DOM做了很多工作,通常在遍历DOM时不会遇到问题。。。也许是早上太早了: MessageBox.Show完全按照预期工作,显示正确的值: 但是,“while”行抛出空指针异常,因为“form”为空(在调试器中确认) 您已到达顶级父级,但未找到匹配的标记名 ie页面上的第一个“h1”(你的el[0])不在表单中。omg谢谢-我假设它在第一次迭代中失败了。。。谢谢;-)现在太早了-标签名都是大写的哈哈,没问题,我们都去过! HtmlElementCollecti

我已经和WebBrowser一起导航DOM做了很多工作,通常在遍历DOM时不会遇到问题。。。也许是早上太早了:

MessageBox.Show完全按照预期工作,显示正确的值:

但是,“while”行抛出空指针异常,因为“form”为空(在调试器中确认)


您已到达顶级父级,但未找到匹配的标记名


ie页面上的第一个“h1”(你的el[0])不在表单中。

omg谢谢-我假设它在第一次迭代中失败了。。。谢谢;-)现在太早了-标签名都是大写的哈哈,没问题,我们都去过!
HtmlElementCollection el = webBrowser.Document.GetElementsByTagName("h1");

MessageBox.Show(el[0].InnerHtml);

HtmlElement form = el[0];

while (form.TagName != "form")
{
   form = form.Parent;
}