0
我有这样的代码:的getElementById不工作
web.Document.GetElementById("idLoginUserName").SetAttribute("value", user);
用户是一个字符串,网络是一个WebBrowser控件。它的下
private void web_Navigated(object sender, WebBrowserNavigatedEventArgs e)
这是页面上的ID:
<input tabindex="100" type="text" name="username" id="idLoginUserName" value="" class="textbox ">
然而,我得到这个错误:
A first chance exception of type 'System.NullReferenceException' occurred in MyProgram.exe
An exception of type 'System.NullReferenceException' occurred in MyProgram.exe but was not handled in user code
调试它,我可以看到,它并试图执行它,并且在尝试时返回该错误。
你有没有试过用'DocumentCompleted'事件,而不是'Navigated',为应答[这里](http://stackoverflow.com/questions/18048920/webbrowser-isnt-wokring)和[这里](HTTP:/ /stackoverflow.com/a/18050820/1906557) – I4V
是的,在它没有工作后,我将它从DocumentCompleted中更改。 – Minicl55
你能确定哪个值是'null'吗?调试器很方便。 – rutter