Detect user click
Asked Answered
D

1

0

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.

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

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.

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.

Any ideas?

Dawdle answered 22/7, 2021 at 9:12 Comment(7)
I know how to do this with input() via command prompt - we can even automate this part. so that you will not have to do any manual interactionPerforate
@Perforate i dont want to manually interact with command prompt and the code will be random based on my cellphones authentication app or are you suggesting another way?Dawdle
in python you can handle command prompt input I believe, we don't need Selenium for command prompt. Could you tell me briefly, what exactly your manual steps.Perforate
@Perforate steps are: (1) execute the script from command prompt; (2) script navigates to website and submits credentials; (3) website displays prompt requesting 2FA code -- at this point, i would like to manually check my phone to get the 2FA code and then manually enter it into the browser and manually click submit, but i cannot think of any practical way to pause execution of the script until i manually hit the "submit" buttonDawdle
@Perforate one way i just thought of was to literally attach a JS addEventListener('click'... with execute_script, but this seems really hackish too :/Dawdle
Check with your ops team, they may give you an environment where you do not need 2FA at all. It should get by pass.Perforate
@Perforate im not crawling my own website... im running this script on the open web. do u have any ideas or no?Dawdle
D
2

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)

Can anybody come up with a better solution?!

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

Dawdle answered 22/7, 2021 at 10:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.