So, I'm creating a bot using webBrowser in c# that loads a website entered in the text box. When the website is loaded, I need bot to click on a specific anchor text. After that when a new page is loaded, I need to click on another anchor text and so on, until a form to fill out details appears. I also need to show captcha to the user where he/she can fill it and submit it, so that the page can continue to next page.
What I need is to invoke different methods, each time the browser navigated to next page and loading is complete. I have successfully created a WebBrowser_DocumentCompleted, but it get invoked over and over again, due to the fact that same hyper link is present on the page that I want to visit. But, on that page I need to click on a button.
I did this for getting the link and visiting it.
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
// Select the html element by inner text of anchor and click on it
HtmlElementCollection elc = this.webBrowser1.Document.GetElementsByTagName("a");
foreach (HtmlElement el in elc)
{
if (el.InnerText == null || el.InnerText.Equals("Matching text"))
{
el.InvokeMember("click");
}
}
}
After this the link that have matched innretext get clicked and the page loads. The page have same anchor text and it gets loaded again and again. But, I need to click on another button and go to next page.
So, if you have any way that I can use to do it then it would be awesome.Any help is welcomed!
P.S. I'm a beginner in C# and .net