-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_3_1_ModalWindow.py
More file actions
38 lines (27 loc) · 1006 Bytes
/
2_3_1_ModalWindow.py
File metadata and controls
38 lines (27 loc) · 1006 Bytes
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
# -*- coding: windows-1251 -*-
from selenium import webdriver
import time
import math
from selenium.webdriver.support.ui import Select
def calc(x):
return str(math.log(abs(12*math.sin(int(x)))))
try:
link = "http://suninjuly.github.io/alert_accept.html"
browser = webdriver.Chrome()
browser.get(link)
button = browser.find_element_by_css_selector("button.btn")
button.click()
alert = browser.switch_to.alert
alert.accept()
x = browser.find_element_by_css_selector("#input_value").text
y = calc(x)
browser.execute_script("window.scrollTo(0,document.body.scrollHeight);")
browser.find_element_by_css_selector("#answer").send_keys(y)
# Îòïðàâëÿåì çàïîëíåííóþ ôîðìó
button = browser.find_element_by_css_selector("button.btn")
button.click()
finally:
# îæèäàíèå ÷òîáû âèçóàëüíî îöåíèòü ðåçóëüòàòû ïðîõîæäåíèÿ ñêðèïòà
time.sleep(10)
# çàêðûâàåì áðàóçåð ïîñëå âñåõ ìàíèïóëÿöèé
browser.quit()