-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest23_2.py
34 lines (25 loc) · 1.1 KB
/
test23_2.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
import time
import math
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
browser = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
link = "http://suninjuly.github.io/alert_accept.html"
def calc(x):
return str(math.log(abs(12 * math.sin(int(x)))))
try:
browser.get(link)
browser.find_element(By.CSS_SELECTOR, "button[type='submit']").click()
browser.switch_to.alert.accept()
x_element = browser.find_element(By.CSS_SELECTOR, "#input_value")
x = x_element.text
y = calc(x)
browser.find_element(By.CSS_SELECTOR, "#answer").send_keys(y)
browser.find_element(By.CSS_SELECTOR, "button[type='submit']").click()
finally:
# успеваем скопировать код за 30 секунд
time.sleep(8)
# закрываем браузер после всех манипуляций
browser.quit()
# не забываем оставить пустую строку в конце файла