Forums

Selenium Error after updating: AttributeError: 'dict' object has no attribute 'click'

Hello Support!

I don't know why, but my script stopped working randomly.

While I was reviewing the forms I found a fix. https://www.pythonanywhere.com/forums/topic/27366/

However, now when selenium tries to interact with an element (in this case a button) and tries to click it.

I get the following message. AttributeError: 'dict' object has no attribute 'click'

I verified that one, on my local app the code works.

I also verified that it detected and found the element.

Can you assist me with this?

You need to inspect what is the object you try to call click method on. Add some logging to your code to check what is that.

I printed out both the CSS selector and also the element (once it finds it).

Python code to print out data:

if driver.find_element(By.CSS_SELECTOR, element["css_selector"]):
    ele = driver.find_element(By.CSS_SELECTOR, element["css_selector"])
    print(f"CSS Selector {element['css_selector']}")
    print(ele)
    ele.click()
    time.sleep(1)

console and webdriver set to headless Print Statements Below:

CSS Selector #cookie-notice-button

{'ELEMENT': '0.745406401239542-2'}

on my local computer with webdriver not set to headless Print Statements Below:

CSS Selector #cookie-notice-button

<selenium.webdriver.remote.webelement.WebElement (session="b7ea82fd455d0484477c6bf47cec240b", element="1360d79e-19f8-47e7-862c-7a0368545158")>

Hi Support!

I looked into this further and it appears headless mode requires you to specify a width and height. https://stackoverflow.com/questions/59420408/how-to-click-button-in-headless-and-button-have-div-tag-inside-it-using-selenium#answers-header

The same error still happens.

Not sure at this moment why this is happening out of the blue.

That looks like you may have a version of selenium that is incompatible with the chromedriver that we have installed. See https://help.pythonanywhere.com/pages/selenium/

The code worked before, it just stopped working.

So not sure why it would just stop allowing me to interact with clickable elements when I could before.

Has selenium been altered on this platform recently?

Were you changing your system image recently?

I only tried updating selenium when the error happened.

I found this form post and followed the steps.

https://www.pythonanywhere.com/forums/topic/29068/

After this didn't fix the issue, I tried reverting it back.

What do you see if you run pip3.8 show selenium, replacing the "3.8" with the actual version of Python that you are using to run your code?

Running the command I get the following:

Name: selenium

Version: 4.1.2

Summary: None

Home-page: https://www.selenium.dev

Author: None

Author-email: None

License: Apache 2.0

Location: /home/keyinora/.local/lib/python3.8/site-packages

Requires: trio, urllib3, trio-websocket

Required-by:

It sounds like you have an incompatible version of selenium installed, then. Try running

pip uninstall selenium

...and then run the pip show command again -- you should see version 3.141.0.