以下问题很多人都经常遇到,而且很多都能百度到解决方法,此处是为了自己方便,在使用之后确定可用的结果做了记录
报错一:
Traceback (most recent call last):
File "D:/Exercise/baidu.py", line 5, in <module>
browser =webdriver.Firefox()
File "D:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 140, in __init__
self.service.start()
File "D:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
解决:
1)此处需要安装Firefox geckodriver
- 下载地址:https://github.com/mozilla/geckodriver/releases
- 解压缩:该软件无需安装,解压缩即可,比如解压缩到路径: D:/browser_drivers/
- 设置环境变量:需将上一步的解压缩路径添加的Windows环境变量中
2)添加Firefox可执行程序到系统环境变量
报错二:
解决:火狐版本不兼容(不一定是高了还是低了,我目前使用的45版本)
报错三:
火狐版本问题
报错四:
用了方法1之后因为出现问题三然后卸载,默认安装路径重装了火狐47、python2.7.9和selenium等等,结果出现问题四
方法1:这里如果你的火狐浏览器安装不是默认路径,需要修改Python的两个文件配置:
配置文件地址: D:\Programs\Python\Python35-32\Lib\site-packages\selenium\webdriver\firefox的
① webdriver.py文件“def__init__(self,firefox_profile=None,firefox_binary=None”,修改为
def_init_(self,firefox_profile=None,firefox_binary=FirefoxBinary(""C:/Program Files (x86)/Mozilla Firefox/firefox.exe"")
② Firefox_binary.py文件
“def __init__(self, firefox_path=None, log_file=None):”修改为
def_init_(self,firefox_path=""C:/Program Files (x86)/Mozilla Firefox/firefox.exe"",log_file=None);
方法2:执行文件中browser = webdriver.Firefox(executable_path="C:\Python27\geckodriver.exe")
报错五:
Traceback (most recent call last):
File "D:\Exercise\baidu.py", line 5, in <module>
browser =webdriver.Ie()
File "D:\Python27\lib\site-packages\selenium\webdriver\ie\webdriver.py", line 57, in __init__
desired_capabilities=capabilities)
File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "D:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones.
解决:
把Internet选项-安全里的保护模式都去掉或者都选上
如果是公司内网使用代理上网,RF无法识别IE的配置需要使用proxy.pac脚本实现代理上网
配置方法 IE》工具》Internet选项》连接》局域网设置
勾选使用自动配置脚本 file://c:/proxy.pac ------脚本存放路径 注意斜杠