1

I am trying to make an automated LinkedIn application bot. The basic idea is to login, search for marketing jobs, click on the 'easy apply' filter, and then apply to the jobs listed, one by one.

I'm only getting halfway there, though. I'm being able to get to the application page and then type my phone number. But, that is only if I exclude the last two lines of code (given in comments in the code block given below). The moment I make the last two lines executable too, the execution doesn't work right the moment it searches for the first easy apply button.

(I intend to use this code only for learning purposes and nothing else)

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import dotenv
import os

dotenv.load_dotenv()

driver = webdriver.Firefox()
driver.get("https://www.linkedin.com/feed/")

email = os.getenv('email')
password = os.getenv('password')

login_button = driver.find_element(By.LINK_TEXT,'Sign in')
login_button.click()

driver.implicitly_wait(10)

email_input = driver.find_element(By.XPATH,'//*[@id="username"]')
password_input = driver.find_element(By.XPATH,'//*[@id="password"]')
signin_button = driver.find_element(By.XPATH,'/html/body/div/main/div[2]/div[1]/form/div[3]/button')

email_input.send_keys(email)
password_input.send_keys(password)
signin_button.click()

driver.implicitly_wait(15)
search_button = driver.find_element(By.XPATH,'/html/body/div[5]/header/div/div/div/div[1]/input')
search_button.send_keys("Marketing")
search_button.send_keys(Keys.ENTER)

driver.implicitly_wait(10)

easyapplybutton = driver.find_element(By.XPATH,'/html/body/div[5]/div[3]/div[2]/div/div[1]/main/div/div/div[1]/div/ul[1]/li[2]/a') 
easyapplybutton.click()
print('s')

driver.implicitly_wait(5)

easyapplybutton2 = driver.find_element(By.XPATH,"//div[@class='jobs-apply-button--top-card']/button[@class='jobs-apply-button artdeco-button artdeco-button--3 artdeco-button--primary ember-view']")
easyapplybutton2.click()

phonenumber = driver.find_element(By.TAG_NAME,'input')
phonenumber.send_keys(os.getenv('phonenumber'))

# nextbutton = driver.find_element(By.CSS_SELECTOR,'[aria-label=Continue to next step]')
# nextbutton.click()
Ajeet Verma
  • 2,938
  • 3
  • 13
  • 24

2 Answers2

2

Could it be related to your selector? I thought it can be because of the quotes.

Try to use it like below:

nextbutton = driver.find_element(By.CSS_SELECTOR,"[aria-label='Continue to next step']")
iko
  • 21
  • 2
2

Just like your other xpath, you need to pass the css_selector within double quotes i.e. "..." and the value of the attribute within single quotes i.e. '...' as follows:

nextbutton = driver.find_element(By.CSS_SELECTOR, "[aria-label='Continue to next step']")

Optimizing your two lines of code into a single line:

driver.find_element(By.CSS_SELECTOR, "[aria-label='Continue to next step']").click()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352