我正在尝试触发输入元素的OnChange事件。更改元素的值不会触发onChange事件。是否可以向浏览器发送按键以触发输入元素的onchange事件。
答案 0 :(得分:0)
是的,可以将按键和按键事件发送到浏览器:
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);
}
};
可以通过以下链接找到完整的样本:
http://dotnetbrowser-support.teamdev.com/documentation/simulating-keyboard-input