Reputation: 1532
Just started experimenting with selenium and chromedriver, and I've an error in a specific configuration.
I always get : 'dict' object has no attribute 'click'
when I call find_element()
method or find_element_by_*
methods.
I've found that the line:
options.add_experimental_option('w3c', False)
caused the issue but didn't understand why and how to fix this.
Questions:
- Is it the normal behaviour ?
- An idea on how to fix this ?
Info : I disabled w3c to be able to retrieve performance logs (Network) for status code.
Here a standalone test code I made :
import os
import json
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
# Get Chrome Driver Fullpath
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
DRIVER_FULLPATH = os.path.join(PROJECT_ROOT, "chromedriver")
# Options
options = Options()
## Enable headless
options.headless = False
# Disable w3c to be able to retrieve performance logs
options.add_experimental_option('w3c', False)
# Specify custom chromedriver path
service = Service(DRIVER_FULLPATH)
# Create a DesiredCapabilities object
capabilities = DesiredCapabilities.CHROME.copy()
# Enable Network logging here too
capabilities['perfLoggingPrefs'] = ['enableNetwork']
# Instantiate the Driver
driver = webdriver.Chrome(options=options, service=service, desired_capabilities={'loggingPrefs': {'performance': 'INFO'}})
# The URL we want to load first (entry point)
url = 'https://www.python.org/'
# Load the page
driver.get(url)
# Get Logs
logs = driver.get_log('performance')
# Go through logs and find latest network response to get code status
for log_index in range(1,len(logs)+1):
message = json.loads(logs[log_index]['message'])['message']
if message and message['method'] == 'Network.responseReceived':
status_code = message['params']['response']['status']
# For demo purpose only print the status
print('Page status : ' + str(status_code))
break
# Select the radio button
elem = driver.find_element_by_class_name("donate-button")
# OR elem = driver.find_element(By.CLASS_NAME, "donate-button")
# This below will fail (raise error) since I disable w3c but how to fix that ?
elem.click()
input('Press ENTER to close the automated browser')
# Exit
driver.quit()
My configuration :
Upvotes: 4
Views: 1864
Reputation: 51
I encountered the exact same situation, but downgrading the selenium version to 3.141.0 solved the problem for me.
Upvotes: 5