0

There is a page loaded in a webBrowser1 object. It has a "button" tag, which is the button that I need to click. It's basic button. No JavaScript, etc.

I tried:

1) to click it with "enter":

webBrowser.Document.GetElementsByTagName("button")[0].Focus();
Sendkeys.Sendwait("{ENTER}");

That didn't work.

2) to call the "click" event:

webBrowser.Document.GetElementsByTagName("button")[0].InvokeMember("click");

That also didn't work because it's not JavaScript.

3) the "click" handler:

webBrowser.Document.GetElementsByTagName("button")[0].Click +=
        new System.EventHandler(button_click1);

This also can not work, because from what I've read, this is an event handler which triggers after the user actually clicks on this button.

So I ran out of options. What else can I try?

2
  • I have used button.InvokeMember("click"); in previous projects and it worked fine. not sure why it's not working for you. Maybe this link will help, stackoverflow.com/questions/2654442/… Commented Oct 29, 2011 at 3:49
  • Have you looked into using Selenium with .Net? You could get some serious record/playback rapid development code generation if you use it. Commented Oct 29, 2011 at 10:31

1 Answer 1

1

you can try like this for capturing the button event in web browser using c#

HtmlElement el = webBrowser1.Document.All["mybutton"];
object obj = el.DomElement;
System.Reflection.MethodInfo mi = obj.GetType().GetMethod("click");
mi.Invoke(obj, new object[0]); 

OR

private void Form1_Load(object sender, EventArgs e)
{
   this.wb.Url = new Uri("https://login.yahoo.com/config/login_verify2?.intl=gr&.src=ym");
   this.wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}
public void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    HtmlElement username = this.wb.Document.All["username"];
    username.SetAttribute("value", "[email protected]");
    HtmlElement pass = this.wb.Document.All["passwd"];
    pass.SetAttribute("value", "passTest");
    HtmlElement goButton = this.wb.Document.All[".save"];
    goButton.InvokeMember("click");

    return;
}

i hope it will helps you

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.