Issue With CefSharp Browser SendKeys

后端 未结 2 826
醉梦人生
醉梦人生 2020-12-10 17:30

I am using chromium browser to automate some task.

Basically I want to load images for that I have to click \"Add Image\" anchor tag on the webpage.

So I can

相关标签:
2条回答
  • 2020-12-10 17:48

    So much time spent, but found the accepted answer useful to get to the bottom of this:

    KeyEvent k = new KeyEvent
    {
        WindowsKeyCode = 0x0D, // Enter
        FocusOnEditableField = true,
        IsSystemKey = false,
        Type = KeyEventType.KeyDown
    };
    
    _browser.GetBrowser().GetHost().SendKeyEvent(k);
    
    Thread.Sleep(100);
    
    k = new KeyEvent
    {
        WindowsKeyCode = 0x0D, // Enter
        FocusOnEditableField = true,
        IsSystemKey = false,
        Type = KeyEventType.KeyUp
    };
    
    _browser.GetBrowser().GetHost().SendKeyEvent(k);
    
    Thread.Sleep(100);
    

    Notice the KeyEventType.KeyDown and then KeyEventType.KeyUp is sent.

    Inspired by CEF Simulate Mousedown and Keysend and CefSharp webpage element click.

    0 讨论(0)
  • 2020-12-10 17:55

    I used your code like this, and it works for me.

    KeyEvent k = new KeyEvent();
    k.WindowsKeyCode = 0x0D;
    k.FocusOnEditableField = true;
    k.IsSystemKey = false;
    k.Type = KeyEventType.Char;
    Browser.GetBrowser().GetHost().SendKeyEvent(k);
    
    0 讨论(0)
提交回复
热议问题