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