我想创建一个自动填充我的Web表单并执行某些操作的应用程序。
我的应用程序有一个显示网页的Web浏览器控件。
生成错误的WebBrowser1_DocumentCompleted
Eventhandler方法的代码
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlDocument obj = (HtmlDocument)webBrowser1.Document;
HtmlElement txtFirst = obj.GetElementById("txtFirstNo");
HtmlElement txtSecond = obj.GetElementById("txtSecond");
HtmlElement chk = obj.GetElementById("Checkbox1");
txtFirst.SetAttribute("value", "111");
txtSecond.SetAttribute("value", "123456");
chk.InvokeMember("CLICK");
HtmlElement btn = obj.GetElementById("Submit1");
btn.InvokeMember("CLICK");
}
它符合
的错误txtFirst.SetAttribute(“value”,“111”);
对象引用没有设置对象的实例我不明白为什么会给出这个错误。
当我检查时,在即时窗口中
txtFirst.SetAttribute(“value”,“111”)
它给出了
{System.Windows.Forms.HtmlElement}
All: {System.Windows.Forms.HtmlElementCollection}
CanHaveChildren: false
Children: {System.Windows.Forms.HtmlElementCollection}
ClientRectangle: {X = 0 Y = 0 Width = 170 Height = 17}
Document: {System.Windows.Forms.HtmlDocument}
DomElement: {mshtml.HTMLInputElementClass}
Enabled: true
FirstChild: null
Id: "txtFirstNo"
InnerHtml: null
InnerText: null
Name: "txtFirstNo"
NextSibling: null
OffsetParent: {System.Windows.Forms.HtmlElement}
OffsetRectangle: {X = 3 Y = 4 Width = 170 Height = 17}
OuterHtml: "<INPUT id=txtFirstNo style=\"BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none; WIDTH: 170px\" value=11104803 name=txtFirstNo>"
OuterText: null
Parent: {System.Windows.Forms.HtmlElement}
ScrollLeft: 0
ScrollRectangle: {X = 0 Y = 0 Width = 170 Height = 17}
ScrollTop: 0
Style: "BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none; WIDTH: 170px"
TabIndex: 0
TagName: "INPUT"