我有一个多行textBox1和webbrowser1
当文档完成时,我希望程序用一行填充元素然后做一些事情然后用第二行重新填充相同的元素等............
代码是:
HtmlEleme ele = webBrowser1.Document.GetElementById("element ID");
if(ele != null)
ele.InnerText = textBox1.Lines[0];
我怎么能做到这一点(for while或.....)以及如何???
我应该把代码放在哪里?
答案 0 :(得分:1)
如果您的浏览器在您点击按钮时将加载页面,您可以按照以下步骤操作:
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()