-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaScriptAlert.py
More file actions
55 lines (35 loc) · 1.05 KB
/
JavaScriptAlert.py
File metadata and controls
55 lines (35 loc) · 1.05 KB
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
51
52
53
54
55
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
browser = webdriver.Firefox()
browser.maximize_window()
url = "https://the-internet.herokuapp.com/javascript_alerts"
browser.get(url)
AlertButton = browser.find_element(By.XPATH, value="//button[normalize-space()='Click for JS Alert']")
AlertButton.click()
alertText = browser.switch_to.alert
alert_txt = alertText.text
print(alert_txt)
time.sleep(5)
alertText.accept()
time.sleep(5)
# second button
cnfBtn = browser.find_element(By.XPATH, value="//button[normalize-space()='Click for JS Confirm']")
cnfBtn.click()
cnfAlert = browser.switch_to.alert
cnfAlert_txt = cnfAlert.text
print(cnfAlert_txt)
time.sleep(5)
cnfAlert.dismiss()
time.sleep(5)
# prompt btn
proBtn = browser.find_element(By.XPATH, value="//button[normalize-space()='Click for JS Prompt']")
proBtn.click()
proAlert = browser.switch_to.alert
proAlert_txt = proAlert.text
print(proAlert_txt)
time.sleep(5)
proAlert.send_keys("Hi, My name is Saurabh Kumar.")
proAlert.accept()
time.sleep(5)
browser.close()