question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[🐛 Bug]: FIND_ELEMENT command return a dict object value

See original GitHub issue

What happened?

I was updated my selenium version to 4.0.0 from 3.141.0. After that webdriver.find_element() returns dict value, but WebElement is expected in that case. Bug reproduced with attached code in 4.0.0 and not relevant for 3.141.0 version.

In images you can review the difference in that versions for return of webdriver.find_element()

SM1 SM

How can we reproduce the issue?

from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.by import By

if __name__ == '__main__':
    driver = WebDriver()
    driver.get('https://www.selenium.dev/')
    element = driver.find_element(by=By.CSS_SELECTOR, value='input[type=search]')
    element.click()

Relevant log output

Traceback (most recent call last):
  File "PycharmProjects/selenium_bug/main.py", line 8, in <module>
    element.click()
AttributeError: 'dict' object has no attribute 'click'

Operating System

MacOS Big Sur

Selenium version

4.0.0

What are the browser(s) and version(s) where you see this issue?

Chrome 94.0.4606.81

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 94.0.4606.61

Are you using Selenium Grid?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
skripnik-bogdancommented, Nov 11, 2021

@VladimirPodolyan Thank you. I have got the same issue with next environment:

  • ChromeDriver 95.0.4638.17
  • Selenium 4.0.0

Tried to experiment with “chrome driver” options and when I disabled options.add_experimental_option('w3c', False) method find_element(By.XPATH, "") again return {WebElement} instead of {dict} and method click()works as usual.

1reaction
VladimirPodolyancommented, Oct 26, 2021

I was figured it out. It’s caused due to using and passing chrome_options.add_experimental_option('w3c', False) into driver instance as options arg. @lucielavickova-tesena May bee you need to delete this option for success passing in your driver version

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: 'dict' object has no attribute 'click' error with ...
AttributeError: 'dict' object has no attribute 'click' error with find_element_by_css_selector() and click() using Selenium and ChromeDriver. ...
Read more >
7. WebDriver API — Selenium Python Bindings 2 documentation
Returns : The command's JSON response loaded into a dictionary object. execute_async_script (script: str, *args) ...
Read more >
Python Return Dictionary From Function - Finxter
To return a dictionary, first create the dict object within the function body, assign it to a variable your_dict , and return it...
Read more >
Shadow DOM in Selenium - Titus on Testing
What's happening is that Selenium looks at return values from script execution commands and if it detects an element, it automatically converts ...
Read more >
Python: Get Dictionary Key with the Max Value (4 Ways) • datagy
This isn't exactly what we'd expected. We were hoping to return 43 , or at least a number! Python dictionaries come built-in with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found