1

I want to start off with a picture:

enter image description here

Lets assume i do have that form in Visual C#.What i want to accomplish now is that i simulate a "PRESSED ENTER KEY" on my keyboard when im in the HTML-ELEMENT "textbox_name". I already tried it with SendKeys.Send("{ENTER}"); which has no effect. I successfully wrote a value into the Box like this:

public void putByClass(String className, String value)
{
    HtmlElementCollection links = webBrowser1.Document.All;

    foreach (HtmlElement link in links)
    {
        if (link.GetAttribute("className") == className)
        {
            link.SetAttribute("value", value);
        }
    }
}

putByClass("textbox_name_class", "John");

After the line link.SetAttribute("value", value); which puts the name "John" into the Box i want to press the "Enter"-Button on the Keyboard. Thank you very much in advance.

user3877230
  • 439
  • 1
  • 5
  • 18

1 Answers1

0

The problem is that you need to wire in event handlers in order to do what you are referring to. Since you are dealing with the webbrowser control you don't have access to the underlying html and JavaScript. You will need to inject javascript: How to inject Javascript in WebBrowser control?

You would have to wire up the event handler yourself. You will basically inject JavaScript to listen for the focus event of the textbox and then call the submit.

Community
  • 1
  • 1
KingOfHypocrites
  • 9,316
  • 9
  • 47
  • 69