-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask9.py
More file actions
56 lines (42 loc) · 1.45 KB
/
task9.py
File metadata and controls
56 lines (42 loc) · 1.45 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
56
import select
import time
from helper.driver import web_driver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
import math
from selenium.webdriver.support.ui import Select
import os
browser = web_driver().driver_init()
link = "http://suninjuly.github.io/alert_accept.html"
# alert = browser.switch_to.alert
# alert_text = alert.text
# alert = browser.switch_to.alert
# alert.accept()
# confirm.dismiss()
# prompt = browser.switch_to.alert
# prompt.send_keys("My answer")
# prompt.accept()
def calc(x):
return str(math.log(abs(12*math.sin(x))))
def test(link):
try:
browser.get(link)
button = browser.find_element(By.CSS_SELECTOR, "button.btn")
button.click()
confirm = browser.switch_to.alert
confirm.accept()
x_text = browser.find_element(By.XPATH, '//span[@id="input_value"]').text
y = calc(int(x_text))
answer = browser.find_element(By.XPATH, '//input[@id="answer"]')
answer.send_keys(f'{y}')
button = browser.find_element(By.CSS_SELECTOR, "button.btn")
button.click()
finally:
# ожидание чтобы визуально оценить результаты прохождения скрипта
time.sleep(10)
if __name__ == "__main__":
try:
test(link)
finally:
# закрываем браузер после всех манипуляций
browser.quit()