Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why Selenium webdriver won't populate form

I’ve got some code that was intended to logon using selenium( selenium-4.7.2) so that I can keep up with job alerts on a popular job site. It’s also a means of keeping my skills up while seeking work.

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.chrome.service import Service
#from webdriver_manager.chrome import ChromeDriverManager

#driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Set up the webdriver
driver = webdriver.Chrome()

# Navigate to the login page
driver.get('https://www.linkedin.com/uas/login')

# Enter your login credentials
driver.find_element_by_id('username').send_keys('elksie@gmail.com')
driver.find_element_by_id('password').send_keys('g')
# Click the "Sign in" button
driver.find_element_by_css_selector('button[type="submit"]').click()

# Wait for the page to load
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'jobs-search-box')))

# Navigate to the job search page
driver.get('https://www.linkedin.com/jobs/search/?currentJobId=3424225432&keywords=data%20analyst&refresh=true')

# Wait for the page to load
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'job-card-container')))

# Extract the job data
job_cards = driver.find_elements_by_class_name('job-card-container')
for job_card in job_cards:
    title = job_card.find_element_by_class_name('job-card-container__title').text
    company = job_card.find_element_by_class_name('job-card-container__subtitle').text
    location = job_card.find_element_by_class_name('job-card-container__bullet').text

    print(title, company, location)

# Close the browser
driver.close()

The lines…

    driver.find_element_by_id('username').send_keys('elksie@gmail.com')
driver.find_element_by_id('password').send_keys('g')

errors with:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'

>Solution :

find_element_by_id has been deprecated. Use driver.find_element(By.ID, 'username')
Import By using:
from selenium.webdriver.common.by import By

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading