Open A Website & Login Using Webbrowser & Selenium With Python 3.9 By Brian Clark
- Brian Clark

- Oct 12, 2021
- 1 min read
I created a program that opens up the UAGC website and logs in. You can copy this code and put it in your favorite IDE or Python IDLE.
''' Program will help kickstart my ASU day
To do:1. Go through Webdriver Documentation
2. Build a tkinter gui for your program/ or use another gui
'''
from selenium import webdriver
from time import sleep
import webbrowser
import subprocess
import os
# Open ASU Login URL MATE!
#Asu_url = 'https://login.ashford.edu/'
## Input for selecting what item is needed
#webbrowser.open_new_tab(Asu_url)
driver = webdriver.Firefox()
driver.get("https://login.ashford.edu/")
# Variables To Store Elements On The Webpage
button = driver.find_element_by_id('okta-signin-submit')
Username = driver.find_element_by_id('okta-signin-username') #search element id
password = driver.find_element_by_id('okta-signin-password')
submit= driver.find_element_by_id('okta-signin-submit')
# Variables for link elements webDriver.findElement(By.xpath("//a[@href='https://ashford.instructure.com/courses/sis_course_id:527046']")).click();
#______________ OPEN A WEBSITE ______________________
sleep(1)
Username.click()
Username.send_keys(" ") #Paste keyboard strokes
sleep(1)
password.click()
password.send_keys(" ")
sleep(1)
submit.click()
sleep(1)
# ____________ Opened Website Complete ______________
# Figured out the solution at stackoverflow https://stackoverflow.com/questions/33062149/python-selenium-write-in-the-text-box-of-a-form
#okta-signin-submit
os.system("notepad UAGC.txt") # Open A Text File
sleep(1)
#print(txt.readlines())
sleep(2)
lines = ['**** _____ Ready To Do Version 1.0 _____***','1.', '2.', '3.','4.','5.']
with open('UAGC.txt', 'w') as f:
for line in lines:
f.write(line)
f.write('\n')
lines = ['1.', '2.', '3.', '4.', '5.']
with open('UAGC.txt', 'w') as f:
for line in lines:
f.write(line)
f.write('\n')
Credit: Alecxe.(2015 Oct) Python: Selenium write in the text box of a form Stackoverflow. https://stackoverflow.com/questions/33062149/python-selenium-write-in-the-text-box-of-a-form#okta-signin-submit



Comments