Advertisement
Guest User

Updated

a guest
Jul 4th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.common.keys import Keys
  3. from selenium.webdriver.support.ui import WebDriverWait
  4. from selenium.webdriver.support import expected_conditions as EC
  5. from selenium.common.exceptions import TimeoutException
  6. from selenium.webdriver.common.by import By
  7. import operator
  8. import time
  9.  
  10. global driver
  11. driver=webdriver.Chrome("C:\\Users\\Max\\Documents\\Python Programs\\Mathletics\\chromedriver.exe")
  12.  
  13. high = int(input("What do you want your maximum score to be? "))
  14.  
  15. def login(username, password):
  16. driver.get("https://community.mathletics.com/signin#/student")
  17. elem = driver.find_element_by_id("ppp-username")
  18. elem.clear()
  19. elem.send_keys(username)
  20. elem2 = driver.find_element_by_id("ppp-user-password")
  21. elem2.clear()
  22. elem2.send_keys(password)
  23. enter = driver.find_element_by_id("ppp-sign-in")
  24. enter.click()
  25.  
  26. def browse():
  27. #assuming that login has just finished
  28. ask="play"
  29. time.sleep(4)
  30. if ask[1] == "e":
  31. #it is learn
  32. print("samplecodesoitdoesntpullanerror, delete later")
  33. else:
  34. #it is play
  35. driver.get(currenturl())
  36. wait = WebDriverWait(driver, 1).until(EC.presence_of_element_located((By.CLASS_NAME, 'go-button')))
  37. gobutton=driver.find_element_by_class_name("go-button")
  38. gobutton.click()
  39. url=driver.current_url
  40. print("Choose your level (1-2) and Go when you are ready!")
  41. Gone = False
  42. while Gone == False:
  43. if url != driver.current_url:
  44. Gone = True
  45. test()
  46.  
  47. def currenturl():
  48. current = driver.current_url
  49. p1 = current[0:52]
  50. p2 = current[58:]
  51. new = p1 + "play?" + p2
  52. return new
  53.  
  54. def question():
  55. elem = driver.find_element_by_css_selector("div.questions-text-alignment.whiteTextWithShadow.question-size-v4")
  56. elem = elem.text
  57. elem = [n for n in str(elem).split(" ")]
  58. elem.pop()
  59. ops = { "+": operator.add, "-": operator.sub }
  60. ans = ops[elem[1]](int(elem[0]),int(elem[2]))
  61. elem = driver.find_element_by_tag_name("input")
  62. elem.send_keys(ans)
  63. elem.send_keys(Keys.RETURN)
  64.  
  65.  
  66. def test():
  67. global high
  68. ##############
  69. Tactical=False
  70. ##############
  71. wait = WebDriverWait(driver, 25).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'div.questions-text-alignment.whiteTextWithShadow.question-size-v4')))
  72. count = 0
  73. while True:
  74. question()
  75. count += 1
  76. if Tactical == True:
  77. if count == high:
  78. False
  79. break
  80. high += 1
  81. print(high)
  82.  
  83. login(input("Username: "), input("Password: "))
  84. browse()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement