selenium3+Python+firefox53 兼容問題


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,再次運行腳本,成功。

 

 把自己郁悶了一天的原因竟然是被自己坑了。。。。記錄一下,長個教訓

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM