-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtask_with_execute_script.py
41 lines (32 loc) · 1.47 KB
/
task_with_execute_script.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
'''
# Тут расположено решение тестового задания по курсу
# "Автоматизация тестирования с помощью Selenium и Python"
# Модуль 2, раздел 2, степ 6
'''
from selenium import webdriver
import math
link = "http://SunInJuly.github.io/execute_script.html"
browser = webdriver.Chrome()
browser.get(link)
# функция, которая находит значение выражения при заданном x
def calc(x):
return str ( math.log( abs( 12 * math.sin( int( x ) ) ) ) )
# находим значение x для выполнения задания
x_in_text = browser.find_element_by_id("input_value")
x_value = x_in_text.text
# считаем значение x
first_answer = calc(x_value)
# скроллим страницу до появления на ней поля ввода в зоне видимости
first_input = browser.find_element_by_id("answer")
browser.execute_script("return arguments[0].scrollIntoView(true);", first_input)
# вводим ответ в поле ввода
first_input.send_keys(first_answer)
# выбираем checkbox
robotCheckbox = browser.find_element_by_id("robotCheckbox")
robotCheckbox.click()
# выбираем radiobutton
robotRadiobutton = browser.find_element_by_id("robotsRule")
robotRadiobutton.click()
# нажимаем кнопку отправить
send_button = browser.find_element_by_class_name("btn-default")
send_button.click()