I have a webbrowser which is loading a website. If the website firing the "completed" event, my HTMLElementCollection shows me a count of "179". If I click on the button and call the same method to get all HTMLElements, it tells me a count of "194". The problem is: if the "completed"-Event is firing, some HTMLElements are not loaded, and needs a longer time, and my HTMLElement which I need to click on it, is missing too.
To explain with code:
private void Webbrowser_DocumentComplete(object pDisp, ref object URL)
{
if (URL.ToString() == "testsite")
{
HtmlElementCollection c1 = webBrowser1.Document.GetElementsByTagName("div");
foreach (HtmlElement e2 in c1)
{
if (e2.GetAttribute("classname") == "btn3")
{
if (e2.InnerText == "follow")
{
e2.InvokeMember("click");
}
}
}
}
}
The count of "c1" is 179.
If I wait 1-2 seconds and click then on a button with the same code like:
private void Button1_Click(object sender, EventArgs e)
{
HtmlElementCollection c1 = webBrowser1.Document.GetElementsByTagName("div");
foreach (HtmlElement e2 in c1)
{
if (e2.GetAttribute("classname") == "btn3")
{
if (e2.InnerText == "follow")
{
e2.InvokeMember("click");
}
}
}
}
The count of "c1" is 194.
The question is: how can I wait some seconds if the page is build completed? I need the count of 194 because there is ONE HTMLElement which I want to click on it!