In [1]:
# Code attribution: Yiyin Shen, Tyler Caraza-Harter
# Imports
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import time
In [2]:
# Get the checkboxes, button, and output field
service = Service(executable_path="chromedriver-win64/chromedriver.exe")
driver = webdriver.Chrome(service=service)
url = "https://pages.cs.wisc.edu/~yw/CS320F23T19.html"
driver.get(url)
checkbox = driver.find_elements("tag name", "input")[1:7]
button = driver.find_elements("tag name", "button")[1]
field = driver.find_element("id", "out_2")
answers = ["A", "B", "C", "D", "E", "F"]
In [3]:
# Click on the checkboxes and try all combinations
for choice1 in range(6):
for choice2 in range(6):
if choice1 != choice2:
checkbox[choice1].click()
checkbox[choice2].click()
button.click()
time.sleep(0.01)
print(answers[choice1] + "," + answers[choice2] + ": " + field.text)
checkbox[choice1].click()
checkbox[choice2].click()
A,B: Incorrect. A,C: Incorrect. A,D: Incorrect. A,E: Incorrect. A,F: Incorrect. B,A: Incorrect. B,C: Incorrect. B,D: Incorrect. B,E: Incorrect. B,F: Incorrect. C,A: Incorrect. C,B: Incorrect. C,D: Incorrect. C,E: Incorrect. C,F: Correct! D,A: Incorrect. D,B: Incorrect. D,C: Incorrect. D,E: Incorrect. D,F: Incorrect. E,A: Incorrect. E,B: Incorrect. E,C: Incorrect. E,D: Incorrect. E,F: Incorrect. F,A: Incorrect. F,B: Incorrect. F,C: Correct! F,D: Incorrect. F,E: Incorrect.
In [4]:
# Remember to quit when it's done
driver.quit()