Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- from selenium.common.exceptions import TimeoutException
- from selenium.webdriver.common.by import By
- import operator
- import time
- global driver
- driver=webdriver.Chrome("C:\\Users\\Max\\Documents\\Python Programs\\Mathletics\\chromedriver.exe")
- high = int(input("What do you want your maximum score to be? "))
- def login(username, password):
- driver.get("https://community.mathletics.com/signin#/student")
- elem = driver.find_element_by_id("ppp-username")
- elem.clear()
- elem.send_keys(username)
- elem2 = driver.find_element_by_id("ppp-user-password")
- elem2.clear()
- elem2.send_keys(password)
- enter = driver.find_element_by_id("ppp-sign-in")
- enter.click()
- def browse():
- #assuming that login has just finished
- ask="play"
- time.sleep(4)
- if ask[1] == "e":
- #it is learn
- print("samplecodesoitdoesntpullanerror, delete later")
- else:
- #it is play
- driver.get(currenturl())
- wait = WebDriverWait(driver, 1).until(EC.presence_of_element_located((By.CLASS_NAME, 'go-button')))
- gobutton=driver.find_element_by_class_name("go-button")
- gobutton.click()
- url=driver.current_url
- print("Choose your level (1-2) and Go when you are ready!")
- Gone = False
- while Gone == False:
- if url != driver.current_url:
- Gone = True
- test()
- def currenturl():
- current = driver.current_url
- p1 = current[0:52]
- p2 = current[58:]
- new = p1 + "play?" + p2
- return new
- def question():
- elem = driver.find_element_by_css_selector("div.questions-text-alignment.whiteTextWithShadow.question-size-v4")
- elem = elem.text
- elem = [n for n in str(elem).split(" ")]
- elem.pop()
- ops = { "+": operator.add, "-": operator.sub }
- ans = ops[elem[1]](int(elem[0]),int(elem[2]))
- elem = driver.find_element_by_tag_name("input")
- elem.send_keys(ans)
- elem.send_keys(Keys.RETURN)
- def test():
- global high
- ##############
- Tactical=False
- ##############
- wait = WebDriverWait(driver, 25).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'div.questions-text-alignment.whiteTextWithShadow.question-size-v4')))
- count = 0
- while True:
- question()
- count += 1
- if Tactical == True:
- if count == high:
- False
- break
- high += 1
- print(high)
- login(input("Username: "), input("Password: "))
- browse()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement