Home > Blockchain >  Why Selenium webdriver won't populate form
Why Selenium webdriver won't populate form

Time:01-06

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('[email protected]')
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 analyst&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('[email protected]')
driver.find_element_by_id('password').send_keys('g')

errors with:

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

CodePudding user response:

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

  • Related