-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.3.6 chrome tabs.py
More file actions
32 lines (25 loc) · 1.04 KB
/
2.3.6 chrome tabs.py
File metadata and controls
32 lines (25 loc) · 1.04 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
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import math
def calc(x):
return str(math.log(abs(12*math.sin(int(x)))))
try:
browser = webdriver.Chrome()
browser.get('http://suninjuly.github.io/redirect_accept.html')
browser.execute_script("document.getElementsByTagName('button')[0].classList.remove('trollface');")
time.sleep(10)
browser.find_element(By.TAG_NAME, 'button').click()
print(browser.window_handles)
new_window = browser.window_handles[1]
browser.switch_to.window(new_window)
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.btn").click()
finally:
# ожидание чтобы визуально оценить результаты прохождения скрипта
time.sleep(10)
# закрываем браузер после всех манипуляций
browser.quit()