检测用户点击 [英] Detect user click

查看:48
本文介绍了检测用户点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自己的凭据登录网站,但 2FA 处于活动状态.因此,我需要一种方法来暂停"脚本,直到我用鼠标手动单击按钮.

I am logging into a website using my own credentials, but 2FA is active. Therefore, I need a way to "pause" the script until I manually click the button with my mouse.

请注意,按钮总是可点击,因此使用像 element_to_be_clickable 这样的显式等待显然是行不通的.

Note that the button is always clickable, so using an explicit wait like element_to_be_clickable obviously will not work.

我知道如何通过命令提示符使用 input() 执行此操作,但我宁愿手动处理浏览器,因为脚本的其余部分也需要手动浏览器交互.

I know how to do this with input() via command prompt, but I would rather deal with the browser manually since the rest of the script also requires manual browser interaction.

我也知道我可以等到脚本检测到一定数量的输入字符,但我不喜欢这种方法,因为打字错误.

I also know that I could wait until the script detects a certain number of inputted characters, but I do not like this approach because typos.

我知道我可以使用显式等待来检测下一页上的内容,但我想避免这种方式,以防我在提交数据之前需要离开键盘.但是,我可以设置一个不合理的长等待期,例如WebDriver(driver, 999999999),但这种方法看起来超级hacky.

I know I could use an explicit wait in order to detect something on the following page, but I want to avoid this way in case I ever need to step away from the keyboard before submitting the data. However, I could set an unreasonably long wait period e.g. WebDriver(driver, 999999999), but this approach seems super hacky.

有什么想法吗?

推荐答案

这里有一个可能并不适合所有人的解决方案.轮询网址...

Here is a solution that may not work for everybody. Poll the URL...

poll_rate = 1
current_url = driver.current_url
while driver.current_url == current_url:
  time.sleep(poll_rate)

谁能想出更好的解决方案?!

我很震惊,几乎不可能以实用的方式检测用户输入.

I am shocked that it is almost impossible to detect user input in a practical manner.

这篇关于检测用户点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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