Skip to content

Instantly share code, notes, and snippets.

@hjwp
Last active September 16, 2017 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hjwp/208d865c6888dffecf423757359b52d1 to your computer and use it in GitHub Desktop.
Save hjwp/208d865c6888dffecf423757359b52d1 to your computer and use it in GitHub Desktop.
selenium alert dismiss repro attempt
geckodriver.log
<html>
<head>
<script>
window.onbeforeunload = function (e) { return 'leaving page warning'; };
</script>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
#!/usr/bin/env python3.6
import unittest
import subprocess
from selenium import webdriver
class DismissAlertTest(unittest.TestCase):
def setUp(self):
self.server = subprocess.Popen([
'python', '-m', 'http.server', '8181'
])
def tearDown(self):
self.server.kill()
def test_dismissing_alert(self):
browser = webdriver.Firefox()
browser.get('http://localhost:8181/')
self.assertIn('hello', browser.find_element_by_tag_name('body').text.lower())
browser.refresh()
browser.switch_to.alert.accept
browser.quit()
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment