This repository was archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchimpTest.py
More file actions
50 lines (38 loc) · 1.63 KB
/
chimpTest.py
File metadata and controls
50 lines (38 loc) · 1.63 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
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium import webdriver
import time
# Initialize the WebDriver
driver = webdriver.Chrome()
# Navigate to the website
driver.get("https://humanbenchmark.com/tests/chimp")
# Accept Cookies
time.sleep(1.5)
try:
driver.find_element(By.XPATH, "//span[contains(text(),'AGREE')]").click()
except Exception:
print("No cookie acceptance button found, or already accepted.")
# Start the test
try:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(),'Start')]"))).click()
except Exception:
print("Start button not found")
try:
while True:
# Wait until the numbers appear
WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "[data-cellnumber]")))
# Find all elements with numbers
numberElements = driver.find_elements(By.CSS_SELECTOR, "[data-cellnumber]")
# Extract numbers and corresponding elements
numbers = [(int(elem.get_attribute("data-cellnumber")), elem) for elem in numberElements]
# Sort the numbers in ascending order
numbers.sort(key=lambda x: x[0])
# Click the elements in the sorted order
for _, number in numbers:
number.click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(),'Continue')]"))).send_keys(Keys.ENTER)
time.sleep(10)
except Exception:
driver.quit()