Tab to recaptcha

前端 未结 2 1936
滥情空心
滥情空心 2021-01-27 15:17

Here\'s the scenario:

I\'m loading a page via a CefSharp browser. When the user clicks a certain button (on the form, not the web page) the page should then focus on the

相关标签:
2条回答
  • 2021-01-27 16:02

    I found a solution that avoided SendKeys and javascript entirely. The CefSharp browser has the ability to simulate key presses and mouse clicks. I ended up just selecting the textbox that preceded the captcha and then tabbing to it.

    chromeBrowser.Focus();
    chromeBrowser.ExecuteScriptAsync("document.getElementsByClassName('txtBox')[0].focus();");
    
    CefSharp.KeyEvent keyEvent = new CefSharp.KeyEvent();
    keyEvent.WindowsKeyCode = (int)Keys.Tab;
    chromeBrowser.GetBrowser().GetHost().SendKeyEvent(keyEvent);
    
    0 讨论(0)
  • 2021-01-27 16:07

    I've tested KeyDown, KeyUp for Tab key and it works but to put a char in a input element we need to use KeyEventType.Char instead. even Tab key in this case act as text tab not for changing focus.

    KeyEvent key = new KeyEvent
    {
        WindowsKeyCode = 0x0D, // Enter you could use '(int)Keys.Enter'
        FocusOnEditableField = true,
        IsSystemKey = false,
        Type = KeyEventType.Char
    };
    
    
    _browser.GetBrowser().GetHost().SendKeyEvent(key);
    
    0 讨论(0)
提交回复
热议问题