0

I am trying to use the find_element_by_id to select the email or username field on the LinkedIn log in page. But I am getting the below error. Can someone help me?

Traceback (most recent call last):
  File "/home/user/Downloads/TestBrowserScript/main.py", line 126, in <module>
    bot.login()
  File "/home/user/Downloads/TestBrowserScript/test.py", line 44, in login
    self.browser.find_element_by_id("username").send_keys(self.email)
AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'

Here is my program

 def login(self):
        try:
            self.browser.get("https://www.linkedin.com/login")
            time.sleep(random.uniform(5, 10))
            self.browser.find_element_by_id("username").send_keys(self.email)
            self.browser.find_element_by_id("password").send_keys(self.password)
            self.browser.find_element_by_css_selector(".btn__primary--large").click()
            time.sleep(random.uniform(5, 10))
        except TimeoutException:
            raise Exception("Could not login!")

I will send additional info if needed. Where am I going wrong?

I triple checked for any typos - I'm using Chrome as the browser of choice for automating this task. I was expecting the script to select the element and then paste in the information needed from self.email.

  • Which version Selenium are you using? If it is the latest one, 'find_element_by_id' is deprecated. You have to use - find_element(By.ID, "") or find_element(By.CSS_SELECTOR, "") – AbiSaran Jan 29 '23 at 15:39
  • Thank you! Editing an old script and didn't know about that change. This saved so much time. – NovaSec Jan 29 '23 at 18:06

0 Answers0