windows環境下使用python+selenium開啟firebox,pythonfirebox

來源:互聯網
上載者:User

windows環境下使用python+selenium開啟firebox,pythonfirebox

通過pycharm安裝selenium

1.配置好python和pycharm,開啟pycharm,點擊左上方的File->Setting->Project Interpreter,點擊右側的添加按鈕

2.在新彈出的視窗中輸入selenium,選擇selenium,點擊左下角的install package,即安裝成功,右側資訊顯示為版本號碼

3.建立一個python類型的檔案,輸入如下測試開啟Firefox瀏覽器的代碼

4.1 運行之後,出現如下報錯

Selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH 

資訊顯示 geckodriver需要在path環境變數中

造成此錯誤的原因是:原生firebox瀏覽器版本較高

解決方案:

下載geckodriver,地址為:https://github.com/mozilla/geckodriver/releases

找到下載目錄,將geckodriver.exe的安裝路徑添加到path裡面

4.2 按如上方法修改後,再次運行出現如下報錯

selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities

資訊顯示geckodriver和selenium版本不相容

我使用的版本 :selenium3.10.0   geckodriver V0.15.0

4.3 改完後依舊有報錯(汗~)

selenium.common.exceptions.SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag

這個報錯費了我很大的力氣才解決了。。。  不管怎麼做,依舊報這個錯誤資訊,將Firefox升到最高版本都不行,最後我將Firefox重裝了一下,將Firefox的安裝路徑添加到path裡(提示一下:path中添加多個路徑時需要用';'英文狀態的分號進行分隔),不知道是我安裝的原因,還是其他,我安裝在d盤時,沒有檔案名稱,檔案路徑是D:\(有可能是造成我允許失敗的原因哦),因此我自己建立了一個目錄,啊啊,終於大功告成了!

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.