Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python selenium - AttributeError: 'dict' object has no attribute 'get_attribute'

I wanted to showcase selenium and instead of starting a complete Java / C# suite I wanted to quickly use Python since it can be done with a single script.

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

print("sample test case started")
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("MyUrl")
element = driver.find_element(By.ID, "Username")
element.send_keys("MyUsername")

driver.close()
print("sample test case successfully completed")

I am getting this error message: AttributeError: 'dict' object has no attribute 'send_keys'

I would seam that find_element method is returning some kind of dict (Dictonary??) object instead of a selenium web element. How can I fix this??

like image 515
Martijn Hiemstra Avatar asked Oct 17 '25 11:10

Martijn Hiemstra


1 Answers

I ran into this exact issue. It seems to be some sort of bug in Selenium 4.0. I have reverted to 3.141.0 (pip install selenium==3.141.0) and it seems to have resolved this issue.

like image 144
Damian Yang Avatar answered Oct 20 '25 01:10

Damian Yang