Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
VladimirPodolian opened this issue Oct 22, 2021 · 15 comments
Closed

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

VladimirPodolian opened this issue Oct 22, 2021 · 15 comments

Comments

@VladimirPodolian
Copy link
Contributor

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?

@github-actions
Copy link

@VladimirPodolyan, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@AutomatedTester
Copy link
Member

davidburns in ~/development/selenium on trunk ● λ python3
Python 3.9.4 (default, Apr  5 2021, 01:50:46) 
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> driver = webdriver.Chrome()
>>> driver.get('https://www.selenium.dev/')
>>> from selenium.webdriver.common.by import By
>>> element = driver.find_element(by=By.CSS_SELECTOR, value='input[type=search]')
>>> element.click()
>>> webdriver.__version__
'4.0.0'

This seems to work for me.

@VladimirPodolian
Copy link
Contributor Author

VladimirPodolian commented Oct 23, 2021

@AutomatedTester Your proposal also not works for me

(Pdb) element.click()
*** AttributeError: 'dict' object has no attribute 'click'
(Pdb) element
{'ELEMENT': '0.6220019529147716-1'}
(Pdb) webdriver.__version__
'4.0.0'

@AutomatedTester
Copy link
Member

it looks like you're connecting to a very old version of Chromedriver, it seems to be returning a the wrong shaped object. What version of chromedriver are you using?

@VladimirPodolian
Copy link
Contributor Author

@AutomatedTester Yeah, you right. I downloaded the latest chromedriver and everything is fine after that. I don't know why it's reproduced in project where i'm working. Mb due to webdriver_manager (Note: driver version is normal in driver.capabilities, but issue still reproduced) that we using. Sorry for issue

@AutomatedTester
Copy link
Member

no worries, glad we got it sorted!

@lucielavickova-tesena
Copy link

hello, I am having the same issue as @VladimirPodolyan, but I need to stick to the chromedriver v93 due to the test environment where is chrome v93 installed... is there a way how to proceed anyway?

@VladimirPodolian
Copy link
Contributor Author

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

@dakshamdev
Copy link

Same issue, Just migrated back to the previous version and it worked fine, seems like it is only in the Chrome Driver Part

@fenchu
Copy link

fenchu commented Nov 8, 2021

I have the same issue: chrome v95,v96, edge v96,v97 Selenium v4.0.0 with python v3.10.0, not in v3.9.7:

chrome v95:

tests\test_08_idproofing_no.py:152: in test02_idproofing
    shadow_root.find_elements(By.CSS_SELECTOR, "span#lang-icon")[0].click()
E   AttributeError: 'dict' object has no attribute 'find_elements'

shadow_root:{'ELEMENT': '0.06690798850173985-2'}

msedge v97:

same error:
shadow_root:{'shadow-6066-11e4-a52e-4f735466cecf': '0.4818716171357742-2'}

To get shadow-root I execute the javascript:

def expand_shadow_element(driver, el, jstype='shadowRoot'):
    """ expand shadow root """
    shadow_root = driver.execute_script(f"return arguments[0].{jstype}", el)
    return shadow_root

chrome_options.add_experimental_option('w3c', False) does not matter

@skripnik-bogdan
Copy link

@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.

@FranciscoPalomares
Copy link

FranciscoPalomares commented Nov 23, 2021

Hi, I have same problems with 'version': '96.0.4664.45' return dict element with remote webdriver

@NickAJScott
Copy link

Yup having the same issue here, but we arn't using the w3c option. Will try updating chrome drivers and see if that helps

@FranciscoPalomares
Copy link

I have problems with remote chromium version: 98.0.4727.0

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants