SeleniumBase/examples/handle_alert_test.py

19 lines
810 B
Python
Raw Normal View History

from seleniumbase import BaseCase
2021-03-11 06:27:52 +08:00
class HandleAlertTests(BaseCase):
def test_alerts(self):
2021-02-25 15:34:07 +08:00
if self.browser == "safari":
self.skip("This test doesn't run on Safari! (alert issues)")
self.open("about:blank")
2021-02-25 15:34:07 +08:00
self.execute_script('window.alert("ALERT!!!");')
2020-05-28 15:37:44 +08:00
self.sleep(1) # Not needed (Lets you see the alert pop up)
self.accept_alert()
self.sleep(1) # Not needed (Lets you see the alert go away)
2020-04-23 00:45:11 +08:00
self.execute_script('window.prompt("My Prompt","defaultText");')
2020-05-28 15:37:44 +08:00
self.sleep(1) # Not needed (Lets you see the alert pop up)
alert = self.switch_to_alert()
self.assert_equal(alert.text, "My Prompt") # Not input field
self.dismiss_alert()
self.sleep(1) # Not needed (Lets you see the alert go away)