如果您的浏览器将在您单击按钮时加载页面,您可以按照以下步骤操作:
bool loaded;
void Operate()
{
string[] lines = TextBox1.Text.Split('\n');
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
for (int i = 0; i < lines.Length; i++)
{
loaded = false;
HtmlElement ele = webBrowser1.Document.GetElementById("element ID");
ele.InnerText = lines[i];
//click a button here
HtmlElement elmbutton = webBrowser1.Document.GetElementById("ButtonID");
elmbutton.InvokeMember("click");
//here wait for web browser navigate.
while (!loaded)
{
System.Threading.Thread.Sleep(10);
Application.DoEvents();
}
}
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
loaded = true;
}
另一方面,我必须警告你Application.DoEvents()