搜索htmlelement时0x80070005(E_ACCESSDENIED)

时间:2014-03-10 05:30:51

标签: c#

我正在尝试在页面上找到提交按钮并使用webbrowser提交表单,这部分代码一直在给我

An unhandled exception of type 'System.UnauthorizedAccessException' occurred in System.Windows.Forms.dll

Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

代码是:

     HtmlDocument pagehtml = this.webBrowser1.Document;
     HtmlElementCollection page = pagehtml.All;

                foreach (HtmlElement element in page)
                {
                    if (element.GetAttribute("type") == "submit") //line that is highlighted during the error
                    {
                        element.InvokeMember("click");
                    }
                }

1 个答案:

答案 0 :(得分:0)

不确定为什么会这样做但我发现了另一种方法

                HtmlElementCollection page = webBrowser1.Document.GetElementsByTagName("input");
                foreach (HtmlElement element in page)
                {
                    if (element.GetAttribute("value").Contains("Submit"))
                    {
                        element.InvokeMember("click");
                    }
                }