遇到的坑-selenium报错:module selenium.webdriver has no attribute chrome

本文记录了一次使用selenium时遇到的奇怪报错:module selenium.webdriver has no attribute chrome。作者在更改脚本文件名后出现此问题,尝试百度和StackOverflow上的解决方案未果。最终发现只需更改回原文件名或使用其他文件名即可解决问题。源码部分并未提供具体的错误原因或解决方法的细节。

问题

今天实在是为了滚固自己之前的selenium知识,写了一个自动化邮件发送脚本,emmm,一切都是正常运行的,emm,结果我改了一下文件名(改为email.py),再运行,报错??????错误提示如下:
AttributeError: partially initialized module 'selenium.webdriver' has no attribute 'Chrome' (most likely due to a circular import)
emmmm,什么鬼

过程

我去网上百度了,也在stackoverflow找到了,根本无法解决额,emmm,重新安装selenium也不行额

解决

额,就是换一个名字就可以了,我是将email.py改为了email_163.py,好了…

源码部分

# -*-encoding:UTF-8 -*-
from selenium import webdriver
import time

web = webdriver.Chrome()
web.get('https://mail.163.com/')
iframe = web.find_element_by_tag_name('iframe')

web.switch_to_frame(iframe)

# 模拟登陆
account = input('你的邮箱账号:')
password = input('你的密码:')
address = input('收件人地址:')
topic = input('邮件主题:')
content = input('邮件内容:\n')
web.find_element_by_name('email').send_keys(account)
web.find_element_by_name('password').send_keys(password)
time.sleep(3)
web.find_element_by_id('dologin').click()

web.switch_to.default_content()
time.sleep(5)
# 写信
xx_butten = web.find_elements_by_xpath('//li[@hidefocus="hidefocus"]')[1].click()
time.sleep(5)
web.find_element_by_class_name('nui-editableAddr-ipt').send_keys(address)
zt = web.find_elements_by_class_name('nui-ipt-input')[2].send_keys(topic)
iframe = web.find_elements_by_tag_name('iframe')[3]

web.switch_to_frame(iframe)
time.sleep(1)
web.find_element_by_class_name('nui-scroll').send_keys(content)
web.switch_to.default_content()
time.sleep(1)
web.find_element_by_class_name('nui-toolbar-item').click()
web.quit()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值