Find any link in a webpage and click/navigate using WebBrowser Class

First of all, i would like to say I was not able to post from Jan-June…as it was a hectic period.I am back now..:)

P.S.:
codes given below worked for me,u all need to find the code snippets to include from debugging.I have striked the parts that need to be changed.

  • If the link/button to be clicked has id,eg.

<span id=”login”>Log On</span>

Here is the code:

HtmlElement button = webBrowser1.Document.GetElementById(“login“);

button.InvokeMember(“click”);

  • If the link/button to be clicked,do not has an id..

foreach (HtmlElement links in webBrowser1.Document.Links)
{
if (links.InnerHtml.StartsWith(“<IMG title=” , StringComparison.OrdinalIgnoreCase))
{
string tempHref = links.OuterHtml;
string[] tempUrl = Regex.Split(tempHref, (“(\”)”));
webBrowser1.Navigate(address+tempUrl[1]);
}
}

Done!! 🙂

Is it?


Leave a comment

Pages

Archives

Current Month

June 2009
S M T W T F S
 123456
78910111213
14151617181920
21222324252627
282930