def login(): # log in to the intranet print('logging in...') try: driver.get('https://intranet.hbtn.io') driver.find_element_by_id('user_login').send_keys(email) driver.find_element_by_id('user_password').send_keys(password) driver.find_element_by_name('commit').click() WebDriverWait(driver, 15).until( EC.visibility_of_element_located((By.CLASS_NAME, 'signed_in'))) except TimeoutException: print('login failed.') driver.quit() exit()
def checker(project, problems): # Check valid problems for count, problem in enumerate(problems): print('checking #' + str(problem) + '...') if count != 0: driver.execute_script('window.open(' ');') driver.switch_to.window(driver.window_handles[count]) driver.get('https://intranet.hbtn.io/projects/' + project) all_problems = driver.find_elements_by_xpath( "//*[contains(text(), 'Check your code?')]") all_problems[problem].click() sleep(1) # wait for check test to appear check = driver.find_elements_by_class_name( 'correction_request_test_admin') check[problem].click()
def __init__(self, driver): driver.get("https://courses.ultimateqa.com/users/sign_up") self.driver = driver self.first_name_field = driver.find_element( By.XPATH, "//input[@placeholder='First Name']") self.last_name_field = driver.find_element( By.XPATH, "//input[@placeholder='Last Name']") self.email_field = driver.find_element( By.XPATH, "//input[@placeholder='Email']") self.new_password_field = driver.find_element( By.XPATH, "//input[@placeholder='New Password']") self.terms_checkbox = driver.find_element(By.XPATH, "//input[@type='checkbox']") self.sign_up_btn = driver.find_element(By.XPATH, "//input[@type='submit']")
def validator(project, problems): # Check that project and problem numbers are valid valid_problems = [] driver.get('https://intranet.hbtn.io/projects/' + project) possible_problems = driver.find_elements_by_xpath( "//*[contains(text(), 'Check your code?')]") if len(possible_problems) == 0: print('There are no problems to check for project ' + project) return valid_problems if problems == 'all': for problem in range(len(possible_problems)): valid_problems.append(problem) return valid_problems for problem in problems: if 0 <= problem < len(possible_problems): valid_problems.append(problem) else: print( str(problem) + ' is not a valid problem number or cannot be checked.') return valid_problems
def __init__(self, driver): driver.get("https://courses.ultimateqa.com/users/password/new") self.email_field = driver.find_element(By.XPATH, "//input[@type='email' and @placeholder='Email']") self.submit_btn = driver.find_element(By.XPATH, "//input[@type='submit']")
def get(url): driver.get(url)