7

I have created a dialog box in browser (this Happens when an error occurs in user input details). What I need is to wait until the user clicks on the dialog box before preceding with automatic execution (only for testing). Here is what I have

# driver is a chrome web driver
driver.execute_script("alert('qwer');")
wait = WebDriverWait(driver, 10)    
element = wait.until(EC.alert_is_present()) 

I tried to search online but only got an answer when a user clicks on a button inside a webpage but not on a generated dialog box. How to do it (if possible)?

4
  • 1
    Hey There, are you looking for a way to wait until the alert box is visible, or would a way to interact with the alert box be useful at all? Commented May 26, 2019 at 14:08
  • You could try to use the builtin time module. I forgot which function you have to call, but there is one that waits for an action, and then executes the following code. Commented May 26, 2019 at 14:16
  • Also out of curiosity - What is the variable "EC" in your posted code? Thanks :) Commented May 26, 2019 at 15:00
  • I just want to wait until the user clicks on the dialog box. Similar to alert,accept() but done by the user. Commented May 26, 2019 at 15:23

1 Answer 1

1
from time import sleep
while EC.alert_is_present()(driver):
    sleep(30)

If you simply want to alert the user then use pymsgbox or Telegram API to send him a message,

from pymsgbox import alert
alert("Hey User")
Sign up to request clarification or add additional context in comments.

6 Comments

Here you are just waiting for a an amount of time. So, it is not possible check for user click?!
See the while condition
Well, it keeps running forever even after I click on ok.
Even after 30s? Reduce the seconds.
If the alert is closed and I try driver.switch_to.alert I get no NoAlertPresentException. So, I think I will catch the exception exit loop when it happens. Thank you.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.