Skip to content

[🐛 Bug]: Python + Selenium 4.0+ (AttributeError: 'dict' object has no attribute 'click') #10171

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

Closed
ElenaStepuro opened this issue Dec 21, 2021 · 12 comments
Labels
C-py Python Bindings I-defect Something is not working as intended J-awaiting answer Question asked of user; a reply moves it to triage again

Comments

@ElenaStepuro
Copy link

What happened?

During running tests on Python faced with issue: AttributeError: 'dict' object has no attribute 'click'
which didn't see on Selenium 3.141

How can we reproduce the issue?

Python 3.8
Exception see with w3c=True and without

Code:
    def setup_method(self):
        options = webdriver.ChromeOptions()
        options.w3c = True
        options.add_argument('--no-sandbox')
        self.driver = webdriver.Remote(
            command_executor="http://localhost:8085",
            desired_capabilities=webdriver.DesiredCapabilities.CHROME,
            options=options)

Test code:
    def test(self, setup_method):
        self.driver.get('https://sha-test-app.herokuapp.com/')
        self.driver.find_element(By.XPATH, "//button[contains(@class,'default-btn')]").click()

Relevant log output

def test(self, setup_method):
        self.driver.get('https://sha-test-app.herokuapp.com/')
        self.button=self.driver.find_element(By.XPATH, "//button[contains(@class,'default-btn')]")
>       self.button.click()
E       AttributeError: 'dict' object has no attribute 'click'

Operating System

Windows 10

Selenium version

4.0.0 and 4.1.0

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

Chrome 94, 95, 96

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

Remote

Are you using Selenium Grid?

No

@ElenaStepuro ElenaStepuro added I-defect Something is not working as intended A-needs-triaging A Selenium member will evaluate this soon! labels Dec 21, 2021
@github-actions
Copy link

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

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

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

Thank you!

@titusfortner
Copy link
Member

First, this error doesn't make sense. If Selenium is getting a return value from find_element() it isn't going to be a dict unless something is getting monkey patched somewhere.

I still tried to reproduce with a Selenium server, but this code works fine for me:

    options = ChromeOptions()
    options.w3c = True
    options.add_argument('--no-sandbox')
    driver = Remote(
        command_executor="http://localhost:4444",
        desired_capabilities=DesiredCapabilities.CHROME,
        options=options)
    driver.get('https://sha-test-app.herokuapp.com/')
    element = driver.find_element(By.XPATH, "//button[contains(@class,'default-btn')]")
    element.click()

That said, you shouldn't be setting w3c any longer, or using desired_capabilities, and you should avoid bypassing the security sandbox unless you've got a good use case for it.

What is running on port 8085? If a Selenium server, what version? If it's a chromedriver, why not use webdriver.Chrome() for this instead?

@titusfortner titusfortner added C-py Python Bindings J-awaiting answer Question asked of user; a reply moves it to triage again and removed A-needs-triaging A Selenium member will evaluate this soon! labels Dec 23, 2021
@ElenaStepuro
Copy link
Author

ElenaStepuro commented Dec 28, 2021

Hello @titusfortner !
I've retried to run code without setting w3c and still has the same exception.
On port 8085 I'm running docker container which I have to called during my test run.
Forget to add while opening this issue: on port 8086 I'm running container which used Selenium Grid 4.0.0-rc-1

@dongfangtianyu
Copy link

I encountered a similar problem during the use of Appium,
image

At this time, find_elenment returned a dict instead of a WebElement.

Unfortunately I cannot reproduce this problem,

Can you print out the return value of find_element, @ElenaStepuro ?
Or maybe provide an environment for others to try ?I'm afraid it's not accidental,

@titusfortner
Copy link
Member

Oh, this makes sense, this is the JSON Wire Protocol signature for elements. You aren't getting a w3c response from the driver.

@ElenaStepuro
Copy link
Author

Hello @dongfangtianyu !
This is what findElement returns
image

@titusfortner
Copy link
Member

Somehow you are getting a jwp session. It should default to w3c, so you're doing something weird.

Appium is slightly harder to get a w3c session.

What is standard out on your console?

@titusfortner
Copy link
Member

I can duplicate this error by setting:

    options.add_experimental_option('w3c', False)

@ElenaStepuro send the exact code you are using, and the console output from the grid. Something it is seeing wants to toggle JSON Wire Protocol, which should not be happening with what you've provided, so something is missing

@dongfangtianyu Getting w3c compliant Appium session is a little trickier.
You can see an example of valid w3c here: https://saucelabs.com/platform/platform-configurator#/

@titusfortner
Copy link
Member

Since this is user setting issues and not a problem with Selenium code, I'm closing this. If people need additional assistance, you can @ me here, contact us in Chat

@JaapHaitsma
Copy link

I had the same error. For me the solution was to update the chromedriver to latest version

@Georgepop
Copy link

yeap, me too

@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 Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-py Python Bindings I-defect Something is not working as intended J-awaiting answer Question asked of user; a reply moves it to triage again
Projects
None yet
Development

No branches or pull requests

5 participants