webbrowser模拟手动输入

时间:2021-11-12 20:22:24

private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("https://www.baidu.com/");
}

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlDocument doc = this.webBrowser1.Document;
HtmlElement keyword = doc.GetElementById("kw");
HtmlElement btn = doc.GetElementById("su");
keyword.Focus();
string customeString = "测试成功了!";
Char[] b = customeString.ToCharArray();
//System.Timers.Timer t = new System.Timers.Timer(1000);
int j = 0;
while (j < 1)
{

for (int i = 0; i < b.Length; i++)//把char数组一个个通过sendkes输入
{
Thread.Sleep(1000);
SendKeys.Send(b[i].ToString());
SendKeys.Flush();

}
j++;
//btn.InvokeMember("click");

 

}