selenium3+Python+firefox53 兼容问题,搞了一天,最后发现是被自己坑了。。。。
电脑安装了,Python2.7 跟Python3
pytho2.7下面是selenium2.4.x
Python3下面是selenium3.x
firefox是53
jdk是1.8
因为电脑jdk环境已经是1.8了,selenium3兼容1.8的,selenium2不兼容1.8的,所有我就用selenium3进行脚本编写
根据selenium3启动firefox高级版本的要求,下载了geckodriver.exe插件,并添加到了环境变量path中
编写脚本如下:
#!/usr/bin/env python# -*- coding:utf-8 -*-from selenium import webdriver driver = webdriver.Firefox()driver.get("http://www.baidu.com") 结果脚本运行错误:
Traceback (most recent call last):
File "G:/pythoncoding/testing/one.py", line 5, in <module>
driver = webdriver.Firefox()
File "D:\biancheng\Python\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 77, in __init__
self.binary, timeout),
File "D:\biancheng\Python\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 49, in __init__
self.binary.launch_browser(self.profile)
File "D:\biancheng\Python\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable()
File "D:\biancheng\Python\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 103, in _wait_until_connectable
raise WebDriverException("Can‘t load the profile. Profile "
selenium.common.exceptions.WebDriverException: Message: Can‘t load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.
各种百度,都说升级版本,但我的都是最新版本了,不需要升级,百度不到我想要的,后来我看了pycharm设置,发现,Python版本选了2.7的。。。
Python2.7中selenium是2.4.x,所以运行脚本一直报错
后来把Python版本选到Python3.x ,Python3.x下的selenium是3.0,再次运行脚本,成功。
把自己郁闷了一天的原因竟然是被自己坑了。。。。记录一下,长个教训