0

This is for a Desktop C# app in Visual Studio Express 2012.

I am trying to use a webBrowser control to automatically logon to various websites but I'm unable to find the LogIn button and issue a 'click' for this particular website. I was able to locate the Username and Password fields and populate values for those without an problem. It's just that I can't seem to issue a 'click' to complete the logon.

The website in question is https://www.my.telstra.com.au/myaccount/home?red=/myaccount/

Using Google Chrome I inspected the code for the LogIn button and found this:

< div class="submit submit_buttons form-row"> < a class="btn-blue" title="Button to Login to My Account" href="javascript:void(0)">Log in < /div>

Any help would be greatly appreciated!

Mick

note this question is a follow-on from a previous question related to same the website WebBrowser website timeout which was answered successfully.

Community
  • 1
  • 1
Michael 1410
  • 73
  • 1
  • 9

1 Answers1

1

Find the button like that

HtmlElementCollection elements = webBrowser1.Document.GetElementsByTagName("a");
//this vill take elements tagget with <a></a>

And then send click

//first find your submit button in <a> tags with the tags diffrence from other <a>'s
//on your code it seem your tags title difrent than other <a>'s 
HtmlElement yourTag;
foreach(HtmlElement o in elements)
{
    if(o.GetAttribute("title")=="Button to Login to My Account")
    {
        yourTag=o;
    }
}
yourTag.InvokeMember("click");

or you can find your button with any diffrent attribute this should work

And if your tag has no diffrence from any other you can find the div contains it with it's class attribute and access its childs and send click with

myHtmlElement.Children[index].InvokeMember("click");
Daniel Abou Chleih
  • 2,440
  • 2
  • 19
  • 31
TC Alper Tokcan
  • 369
  • 1
  • 13
  • You could improve your code by removing yourTag and invoke the Member inside the if with `o.InvokeMember("Click");` in Conncetion with `break;`. Further you should check your code, there are some spelling errors. Apart from that: Good. – Daniel Abou Chleih Oct 23 '13 at 13:51
  • Thanks TC and Daniel - this works brilliantly!! HtmlElementCollection elements = webBrowser1.Document.GetElementsByTagName("a"); foreach (HtmlElement o in elements) { if (o.GetAttribute("title") == "Button to Login to My Account") { o.InvokeMember("Click"); break; } } – Michael 1410 Oct 24 '13 at 11:18