The most irritating and time consuming thing that I ever came across is our college's website. Every time we needed to login to the site in order to check the attendance or to just quickly check the timetable. So I thought to automate this task with the help of selenium framework in python.
This is how I implemented it:
1.Import Libraries:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Note: Before importing we must install selenium by running pip install seleinum in the command line, then download the chrome webdriver from here: https://chromedriver.chromium.org/downloads
2.Then I initialized the chrome webdriver:
PATH="C:\Program Files (x86)\chromedriver"
driver=webdriver.Chrome(PATH)
driver.get("https://vtop.vitbhopal.ac.in/vtop/")
#This is the site link
3.Clicking the login button
With the help of inspect option in chrome web browser I found out the class of the button and then specified it in the code.
As there is no other elements in the home page with the same class there will be no error generated. And we use the click()
method in order to click the button.
vtop=driver.find_element_by_class_name("btn-primary")
vtop.click()
4.Typing in the username and password
As we have done in the previous step, we must find the id of the username and the password from the inspect tab and then we must specify it in the code.
driver.implicitly_wait(5)
user_input=driver.find_element_by_name("uname")
pass_input=driver.find_element_by_name("passwd")
user_input.send_keys("20BSE10789")#enter your username
pass_input.send_keys("Pranav@2002")#enter your password
We must ensure that selenium checks for the elements after the page is fully loaded . So for that we use:
driver.implicitly_wait(5)
This ensures that selenium waits for 5 seconds rather than throwing any error.
5.Typing in the Captcha
We need to type in the captcha manually as it is hard to automate captcha. After the captcha is typed in , the automation will resume. This is achieved by the following code.
bt_submit = driver.find_element_by_id("captcha")
WebDriverWait(driver, timeout=1000, poll_frequency=1) \
.until(EC.staleness_of(bt_submit))
print("signed in")
This code ensures that Selenium waits for the user to click the sign in button (check every 1s with a 1000s timeout).
6.Viewing the attendance and Time Table
This is the last part of the code. Here, the time table and attendance tab are located under a drop-down menu , I wasn't able to access it directly using the class or ID.
So at first I accessed the main menu element with the help of class mentioned inside the span element:
driver.implicitly_wait(5)
select=driver.find_element_by_xpath('.//span[@class = "fa fa-graduation-cap"]')
select.click()
After that I accessed the submenu item with the find_element_by_link_text() method
select=driver.find_element_by_link_text('Time Table')#Use Attendance here instead of Time table to view attendance
select.click()
This way we can see the Time Table/Attendance easily.
Top comments (0)