-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptEcon.py
71 lines (51 loc) · 1.93 KB
/
scriptEcon.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import time
import winsound
import logging
# <div id="qf1" class="shiny-text-output shiny-bound-output" aria-live="polite">The answer is not correct. Try again!</div>
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
service = Service("C:\chromedriver.exe")
service.start()
driver = webdriver.Remote(service.service_url)
# Gets the link and opens a chrome page
driver.get('http://hhsievertsen.shinyapps.io/Economic_data_202122_Quiz/')
# Vars
ans = 101000
myId = 2207234
questionSelector = driver.find_element_by_link_text("Question 9")
studentIDEnter = driver.find_element_by_id("studentid")
answerfield = driver.find_element_by_id("qa9")
answerSubmitButton = driver.find_element_by_id("qb9")
solved = False
# functions
questionSelector.click()
studentIDEnter.send_keys(myId)
studentIDEnter.send_keys(Keys.DELETE)
answerfield.send_keys(ans)
answerSubmitButton.click()
time.sleep(1.5)
# This is the element change to check every loop for a change ofa answer
element = driver.find_element_by_xpath(
'/html/body/div[1]/div/div[1]/div/div[2]/div/div[9]/div[3]').text
print(element)
# Loop to increment and check answer
while solved == False:
if element == "The answer is not correct. Try again!":
ans += 1
answerfield.click()
answerfield.clear()
#ans = round(ans, 2)
answerfield.send_keys(ans)
answerSubmitButton.click()
time.sleep(0.2)
element = driver.find_element_by_xpath(
'/html/body/div[1]/div/div[1]/div/div[2]/div/div[9]/div[3]').text
else:
solved = True
# Beep and stop when the right answer is found, so I can do other stuff in the meantime :)
winsound.Beep(440, 500)
# need a small delay for every test
time.sleep(500)
driver.quit()
# q 8 /html/body/div[1]/div/div[1]/div/div[2]/div/div[8]/div[3] <--This element should be changed for each question attempted