I am trying to fire OnChange event of an input element. Changing the value of the element does not fire onChange event. Is it possible to send a keypress to the browser in order to fire onchange event of the input element.
Asked
Active
Viewed 745 times
1
-
Are you handling the input fields like shown in the following sample? http://dotnetbrowser-support.teamdev.com/samples/handling-form-fields – Anna Dolbina Jan 03 '17 at 06:59
-
In addition, you can simply simulate the DOM event for the particular node: http://dotnetbrowser-support.teamdev.com/documentation/emulate-dom-events – Anna Dolbina Jan 03 '17 at 07:27
1 Answers
0
Yes, it is possible to send key down and key up events to the browser:
browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
{
if (e.IsMainFrame)
{
// The page is loaded completely. Press TAB key to set focus to text field.
KeyParams paramers = new KeyParams(VirtualKeyCode.TAB, ' ');
browser.KeyDown(paramers);
browser.KeyUp(paramers);
// Type 'Hello' text in the focused text field.
paramers = new KeyParams(VirtualKeyCode.VK_H, 'H');
browser.KeyDown(paramers);
browser.KeyUp(paramers);
paramers = new KeyParams(VirtualKeyCode.VK_E, 'e');
browser.KeyDown(paramers);
browser.KeyUp(paramers);
paramers = new KeyParams(VirtualKeyCode.VK_L, 'l');
browser.KeyDown(paramers);
browser.KeyUp(paramers);
paramers = new KeyParams(VirtualKeyCode.VK_L, 'l');
browser.KeyDown(paramers);
browser.KeyUp(paramers);
paramers = new KeyParams(VirtualKeyCode.VK_O, 'o');
browser.KeyDown(paramers);
browser.KeyUp(paramers);
}
};
The complete sample can be found by the following link:
http://dotnetbrowser-support.teamdev.com/documentation/simulating-keyboard-input

Anna Dolbina
- 1
- 1
- 8
- 9
-
Thanks this solves my problem to some extend but is there any other way to fire onchange event of an input element also how to set focus on an input element. – SR_P Jan 03 '17 at 11:15
-
Have you tried to simulate the `change` DOM event for the input element? – Anna Dolbina Jan 19 '17 at 14:14