DEV Community

Cover image for Selenium Webdriver for Automation
Damon Marc Rocha II
Damon Marc Rocha II

Posted on

Selenium Webdriver for Automation

So I recently wanted to create an application to automate the job application process. This project is still a work in progress and was really just meant to be a break from what I have been working on. Using selenium and Monster's easy application process, I got my program to apply to various speed-apply jobs.

Setup

First I imported requests and webdriver from selenium. Then got the monster job URL for software jobs in texas and passed it into my chrome driver

import requests
from selenium import webdriver
URL = 'https://www.monster.com/jobs/search/?q=Software-Developer&where=texas'
driver = webdriver.Chrome(chromedriver_location)
driver.get(URL)
Enter fullscreen mode Exit fullscreen mode

Then the program logged me in using the code below:

driver.find_element_by_tag_name("ul a").click()
driver.find_element_by_id("email").send_keys("email")
driver.find_element_by_id("password").send_keys("password")
driver.find_element_by_id("btn-login").click()
Enter fullscreen mode Exit fullscreen mode

Job Application

When I first started this I tried to go through each application and have the program fill in my information and apply. This worked well for one job but the driver was slower than the code and caused some issues. So I decided to just select the speed-apply jobs and apply to these. However, the issue then arose that the page some times had different numbers of jobs so I implemented the solution below:

for num in range(0, 50):
    try:
        jobs = driver.find_elements_by_tag_name('h2 a')
        jobs[num].click()
    except:
        driver.find_element_by_class_name('mux-search-results').click()
        jobs = driver.find_elements_by_tag_name('h2 a')
        jobs[num].click()
    try:
        apply = driver.find_element_by_id('speedApply')
        if apply:
            apply.click()
            print(f"applied to job {num}")
    except:
        print(f"job {num}")
        print("Gotta do more")
Enter fullscreen mode Exit fullscreen mode

In this code, I go through 50 jobs(Sometimes). If there are no more jobs the program then presses the more jobs button. Once these results are loaded the program will try to continue through the process. This works for the most part but as of now, I am running into issues with some of the speed applies.

With this, I have successfully applied for a handful of jobs on Monster using Selenium and python code.

Latest comments (2)

Collapse
 
dmarcr1997 profile image
Damon Marc Rocha II

Thanks Derek

Collapse
 
derekjhopper profile image
Derek Hopper

This is awesome. Clever use of Selenium.