DEV Community

Cover image for Automating my college's website.
Pranav Ajay
Pranav Ajay

Posted on

Automating my college's website.

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 import WebDriverWait
from import expected_conditions as EC

Enter fullscreen mode Exit fullscreen mode

Note: Before importing we must install selenium by running pip install seleinum in the command line, then download the chrome webdriver from here:

2.Then I initialized the chrome webdriver:

PATH="C:\Program Files (x86)\chromedriver"


#This is the site link
Enter fullscreen mode Exit fullscreen mode

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.

Alt Text

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.

Enter fullscreen mode Exit fullscreen mode

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.

user_input.send_keys("20BSE10789")#enter your username
pass_input.send_keys("Pranav@2002")#enter your password

Enter fullscreen mode Exit fullscreen mode

We must ensure that selenium checks for the elements after the page is fully loaded . So for that we use:

Enter fullscreen mode Exit fullscreen mode

This ensures that selenium waits for 5 seconds rather than throwing any error.

5.Typing in the Captcha

Alt Text

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) \
print("signed in")
Enter fullscreen mode Exit fullscreen mode

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.
Alt Text
So at first I accessed the main menu element with the help of class mentioned inside the span element:

select=driver.find_element_by_xpath('.//span[@class = "fa fa-graduation-cap"]')
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

This way we can see the Time Table/Attendance easily.

Top comments (0)