-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathtest_alerts.py
50 lines (39 loc) · 1.45 KB
/
test_alerts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
global url
url = "https://www.selenium.dev/documentation/webdriver/interactions/alerts/"
def test_alert_popup():
driver = webdriver.Chrome()
driver.get(url)
element = driver.find_element(By.LINK_TEXT, "See an example alert")
driver.execute_script("arguments[0].click();", element)
wait = WebDriverWait(driver, timeout=2)
alert = wait.until(lambda d : d.switch_to.alert)
text = alert.text
alert.accept()
assert text == "Sample alert"
driver.quit()
def test_confirm_popup():
driver = webdriver.Chrome()
driver.get(url)
element = driver.find_element(By.LINK_TEXT, "See a sample confirm")
driver.execute_script("arguments[0].click();", element)
wait = WebDriverWait(driver, timeout=2)
alert = wait.until(lambda d : d.switch_to.alert)
text = alert.text
alert.dismiss()
assert text == "Are you sure?"
driver.quit()
def test_prompt_popup():
driver = webdriver.Chrome()
driver.get(url)
element = driver.find_element(By.LINK_TEXT, "See a sample prompt")
driver.execute_script("arguments[0].click();", element)
wait = WebDriverWait(driver, timeout=2)
alert = wait.until(lambda d : d.switch_to.alert)
alert.send_keys("Selenium")
text = alert.text
alert.accept()
assert text == "What is your tool of choice?"
driver.quit()