Skip to content

Instantly share code, notes, and snippets.

@roman4ello
Last active January 17, 2022 10:13
Show Gist options
  • Save roman4ello/d6fedb35475a00a8f7c942151a73dc5f to your computer and use it in GitHub Desktop.
Save roman4ello/d6fedb35475a00a8f7c942151a73dc5f to your computer and use it in GitHub Desktop.
AttributeError: 'dict' object has no attribute ... error .... using Selenium and ChromeDriver
Latest changes on selenium and chromedriver may result in errors like:
[AttributeError: 'dict' object has no attribute ... error .... using Selenium and ChromeDriver]
To fix this:
1. Implement a step to check if this dict in the result.
2. Create WebElement from the value of the dictionary.
Here is an example of the code:
def get_web_element_from_dict_if_it_is(driver: WebDriver, element_to_check_for_dict):
if type(element_to_check_for_dict) is dict:
first_element_value = list(element_to_check_for_dict.values())[0]
element_to_check_for_dict = driver.create_web_element(element_id=first_element_value)
return element_to_check_for_dict
PS:
- If your current result is dict - it will create a new element from the value in the dictionary.
- If it is not a dictionary you will use this element as usual.
This approach can be related to any selenium method for operating with selenium element (find the element, execute script) and any language which uses selenium(python, java, etc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment