选项卡以重新捕获 [英] Tab to recaptcha

查看:84
本文介绍了选项卡以重新捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这种情况下:

我正在通过CefSharp浏览器加载页面。当用户单击某个按钮(在表单上,​​而不是在网页上)时,该页面应集中在Recaptcha上。

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 recaptcha.

我已经尝试过使用SendKeys来切换到验证码,但似乎没有注册一次,而是似乎多次注册并最终集中在验证码右下方的条款链接,而不是复选框。

I've tried using SendKeys to tab to the captcha, but instead of the tab being pressed once it seems to register multiple times and ends up focusing on the 'Terms' link in the bottom right of the captcha instead of the checkbox.

我也尝试使用chromeBrowser.ExecuteScriptAsync()方法在页面上运行javascript。我可以成功地专注于文本框,甚至可以从这些文本框中运行按键事件,但是当我在前面的文本框中运行选项卡按键事件时,仍然不会突出显示Recaptcha。

I've also tried using the chromeBrowser.ExecuteScriptAsync() method to run javascript on the page. I can successfully focus on textboxes and even run keypress events from those textboxes, but when I run a tab keypress event on the preceding textbox the recaptcha is still not highlighted.

chromeBrowser.Focus();
chromeBrowser.ExecuteScriptAsync("document.getElementsByClassName('txtBox')[0].Focus();" +
"document.getElementsByClassName('txtBox')[0].value = 'test string';")
SendKeys.Send("{TAB}");
SendKeys.Send("{ENTER}");

我还添加了一个事件侦听器,用于确认Tab是否确实被按下

I've also added an event listener that confirms that the Tab is indeed being 'pressed'

chromeBrowser.Focus();
chromeBrowser.ExecuteScriptAsync("document.getElementsByClassName('txtBox')[0].addEventListener('keypress', function(){" +
"alert('something was pressed!');});" +
"document.getElementsByClassName('txtBox')[0].focus();" +
"document.getElementsByClassName('txtBox')[0].value = 'test value';" +
"var e = document.createEvent('KeyboardEvent');" +
"e.initKeyboardEvent('keypress', true, true, document.defaultView, 9, 0, '', false, '');" +
"document.getElementsByClassName('txtBox')[0].dispatchEvent(e);");

我尝试了在页面上显示在recapctha上的每个类名的getElementsByClassName进行检查,然后设置焦点对此。我尝试在Recaptcha iFrame的ID上尝试使用getElementById并将焦点设置为该元素。

I've tried getElementsByClassName for every classname that shows on the recapctha in a page inspect and then setting focus to that. I've tried getElementById on the ID of the recaptcha iFrame and setting focus to that. Nothing focuses on the captcha.

我没主意了。任何帮助将不胜感激。

I'm out of ideas. Any help would be appreciated.

推荐答案

我找到了一个完全避免使用SendKeys和javascript的解决方案。 CefSharp浏览器可以模拟按键和鼠标单击。我最终只是选择了验证码之前的文本框,然后将其切换到该文本框。

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);

这篇关于选项卡以重新捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆