Thursday, April 2, 2009

C#- Workaround for inconsistent behaviour of invokemember in webbrowser control



Today I have encountered an strange issue when using invokemember for clicking input box using C#/.net webbrowser control.
Initially I used below code for clicking many input tags in a webpage.

HtmlElementCollection inputtags = webBrowser1.Document.GetElementsByTagName("input");

foreach (HtmlElement inputtag in inputtags)
{
inputtag.InvokeMember("click");
}


The above code works only for the first input box. It didn't work for remaining input tags.
After changing the code as below it started working for all input tags.

HtmlElementCollection inputtags = webBrowser1.Document.GetElementsByTagName("input");
int tagcount=inputtags.Count;
int loopvar=0;


while (loopvar < tagcount)
{
webBrowser1.Document.GetElementsByTagName("input")[loopvar].InvokeMember("click");
loopvar++;
}

More Articles...

No comments:



Thanks for visiting our blog


twitterrss facebook linkedin YouTube subscribe


Subscribe via email

Enter your email address: