Skip to content

Instantly share code, notes, and snippets.

@J3698
Last active February 2, 2021 19:00
Show Gist options
  • Save J3698/6796d711747a92c99bc5bf3dfcbcd643 to your computer and use it in GitHub Desktop.
Save J3698/6796d711747a92c99bc5bf3dfcbcd643 to your computer and use it in GitHub Desktop.
Duo
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
def login_to_autolab(wd, username, password):
wd.get("https://autolab.andrew.cmu.edu")
present = EC.presence_of_element_located((By.ID, 'username'))
WebDriverWait(wd, 5).until(present)
element = wd.find_element_by_id("username")
element.send_keys(username)
element = wd.find_element_by_id("passwordinput")
element.send_keys(password)
element = wd.find_element_by_class_name("loginbutton").click()
# wait for login
i = 0
two_factored = False
while True:
sleep(3)
try:
iframe = wd.find_element_by_id("duo_iframe")
wd.switch_to.frame(iframe)
wd.find_element_by_name("dampen_choice").click()
sleep(5)
elems = wd.find_elements_by_class_name("auth-button")
if len(elems) != 0:
elems[0].click()
except NoSuchElementException:
pass
elems = wd.find_elements_by_xpath('//*[@title="Go to Course Page"]')
if len(elems) != 0:
break
if i % 5 == 0:
print("waiting for login")
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment