我正在尝试以编程方式访问此网页中的文本框,但我得到“对象引用未设置为对象实例”。这是我的C#程序
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(mainURL);
//设置标题&用户代理
request.ContentType = "charset=iso-8859-7;windows-1253;charset=iso-8859-8;windows-1254;";
WebClient wc = new WebClient();
WebBrowser b = new WebBrowser();
wc.Encoding = Encoding.UTF8;
try
{
b.Navigate(mainURL);
while (b.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
MessageBox.Show("Loaded");
HtmlElement userName = b.Document.GetElementById("jm");
userName.SetAttribute("value", "AA");
此网址的HTML是
<html>
<head>
<title>ARES - Economic entities - Entry form</title>
<meta content="text/html;ISO-8859-2" http-equiv="Content-type">
<link rel="stylesheet" type="text/css" href="css_form.css" media="all">
<link rel="stylesheet" type="text/css" href="css_general.css" media="all">
<style type="text/css">
/* explicit attribute of form elements - xx */
#jm {width: 13em;}
#vyst {width: 10em;}
#ob {width: 13em;}
#ic {width: 8.6em; _width: 8.8em;}
#view {width: 10em;}
</style>
<script language="JavaScript" type="text/javascript" src="js_cookie.js"></script>
<script language="JavaScript" type="text/javascript" src="js_form.js.en"></script>
</head>
<body class="BForm" id="FES">
<form name="f_ares_frup" action="/cgi-bin/ares/ares_es.cgi" method="get" target="vystup">
<input name="jazyk" type="hidden" value="en">
<div>
<table class="TForm">
<tr>
<td class="ttl">Business name:</td>
<td class="inp"><input id="jm" name="obch_jm" maxlength="255" size="20" tabindex="2"></td>
<td class="ttl">Reg.No.:</td>
<td class="inp"><input class="FFocus" id="ic" maxlength="8" name="ico" size="8" tabindex="1"></td>
</tr>
<tr>
<td class="ttl">View:</td>
<td class="inp">
<select id="view" name="maxpoc" tabindex="13">
<option selected="selected" value="200">200 rec.</option>
<option value="500">500 rec.</option>
<option value="1000">1000 rec.</option>
</select>
</td>
</tr>
<tr>
</tr>
<tr>
<td colspan="6" class="TButtArea"><input alt="LookUp" class="aresButt" type="submit" value="Search" tabindex="16"></td>
</tr>
</table>
</div>
</form>
</body>
</html>
我错过了什么? 谢谢 Rashmi