Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Automation of Assignment Submisison
# selenium for web driving
import selenium
from selenium import webdriver
# time for pausing between navigation
import time
# Datetime for recording time of submission
import datetime
# os for file management
import os
def submit_assignment(file_tup):
# Using Chrome to access web
driver = webdriver.Chrome()
# Open the website
# Password for Canvas
with open('C:/Users/Will Koehrsen/Desktop/cp.txt', 'r') as f:
cp =
# Locate id and password
id_box = driver.find_element_by_name('username')
pass_box = driver.find_element_by_name('password')
# Send login information
# Click login
login_button = driver.find_element_by_name('submit')
# Find and click on list of courses
courses_button = driver.find_element_by_id('global_nav_courses_link')
# Wait for the page to load
# Get the name of the folder
folder = file_tup[0]
# Class to select depends on folder
if folder == 'DSCI451':
class_select = driver.find_element_by_link_text('Applied Data Science Research (100/5047)')
elif folder == 'DCSI453':
class_select = driver.find_element_by_link_text('Data Science: Statistical Learning, Modeling and Prediction (100/5046)')
elif folder == 'EECS491':
class_select = driver.find_element_by_link_text('Artificial Intelligence: Probabilistic Graphical Models (100/10039)')
elif folder == 'EECS531':
class_select = driver.find_element_by_link_text('Computer Vision (100/10040)')
# Click on the specific class
assignment_button = driver.find_element_by_link_text('Assignments')
# Wait for the page to load
# Locate the specific assignment
file_name = file_tup[1]
file_locator = file_name.split('.')[0]
specific_assigment = driver.find_element_by_link_text(file_locator)
# Click on the button to submit an assignment
submit_assignment_button = driver.find_element_by_link_text('Submit Assignment')
# If assignment has already been submitted
print('Assignment already submitted, re-submitting')
submit_assignment_button = driver.find_element_by_link_text('Re-submit Assignment')
# Wait for the page to load
# Choose file button
choose_file = driver.find_element_by_name('attachments[0][uploaded_data]')
# Send the name of the file to the button
file_location = os.path.join(submission_dir, folder, file_name)
submit_assignment = driver.find_element_by_id('submit_file_button')
# Wait for the page
# Move the file to the submitted folder
submitted_dir = 'C:/Users/Will Koehrsen/Desktop/submitted_assignments'
submitted_dir = os.path.join(submitted_dir, folder)
submitted_file_name = 'Submitted ' + file_name
submitted_file_location = os.path.join(submitted_dir, submitted_file_name)
# os.rename(file_location, submitted_file_location)
print('{} Assignment for Class {} successfully submitted at {}.'.format(
file_name, folder,'%Y-%m-%d %H:%M:%S')))
print('Submitted assignment available at {}.'.format(submitted_file_location))
if __name__ == "__main__":
# Build tuple of (folder, file) to turn in
submission_dir = 'C:/Users/Will Koehrsen/Desktop/completed_assignments'
dir_list = list(os.listdir(submission_dir))
for directory in dir_list:
file_list = list(os.listdir(os.path.join(submission_dir, directory)))
if len(file_list) != 0:
file_tup = (directory, file_list[0])
if len(file_tup) == 0:
print('No files to submit')
print('Assignment "{}" for "{}" found.'.format(file_tup[1], file_tup[0]))
input('Press enter to proceed: ')
Copy link

miGa77 commented Oct 10, 2020

Thanks for the code! I found it through your blog post. Gonna adjust it a little bit to use it for the same reason ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment