4

I want create alert window in browser.

browser = webdriver.Firefox(
    executable_path=geckodriver_path,
    log_path=geckodriver_log_path
)
browser.get(url)

To create alert window I doing:

browser.execute_script("alert('qwer');")

or

browser.execute_script("return alert('qwer');")

or

browser.execute_script("return (function(){alert('qwer'); return 0;})();")

In all cases alert window was displayed. But in all cases I have an Exception: selenium.common.exceptions.WebDriverException: Message: Failed to find value field.

What is right way to create alert window?

1
  • Can you try a different browser? Chromedriver for example. It appears to be a Firefox-related issue. Commented Mar 22, 2017 at 8:57

1 Answer 1

4

This seem to be geckodriver issue. Despite of generated "Failed to find value field" exception you still can handle opened alert, so you might apply below workaround:

from selenium.common.exceptions import WebDriverException

try:
    browser.execute_script("alert('qwer');")
except WebDriverException:
    pass
browser.switch_to.alert.text # output is "qwer"
browser.switch_to.alert.accept() # alert closed

...or, as was mentioned in comments, you can use Chrome, IE, etc

Sign up to request clarification or add additional context in comments.

Comments

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.