'dict' object has no attribute 'Keys'
时间: 2023-10-07 10:07:12 浏览: 179
解决运行出现dict object has no attribute has_key问题
5星 · 资源好评率100%
这个错误发生在运行原书代码时,错误提示为"AttributeError: 'dict' object has no attribute 'key'"。这意味着在代码中使用了一个字典对象,但是却尝试访问了'key'属性。根据引用中的描述,按照理论上的情况,teacher对象的类型应该是selenium.webdriver.remote.webelement.WebElement,但是却变成了字典(dict)对象。这个问题可以追溯到引用中的代码"color_name=random.choice(lTHECOLORS.keys())"。根据引用中的描述,这是原书的源代码。在Python 3中,字典的keys()方法已经被弃用,应该使用字典的keys()方法来获取字典中所有的键。因此,将代码中的"lTHECOLORS.keys()"替换为"list(lTHECOLORS.keys())"应该解决这个问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [AttributeError: ‘dict‘ object has no attribute ‘key](https://blog.csdn.net/nownow_/article/details/107227930)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [Python运行selenium时报错‘dict‘ object has no attribute ‘send_keys‘解决fang‘an](https://blog.csdn.net/weixin_52709752/article/details/123842752)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文