【學習日誌】Python selenium錯誤__Python

來源:互聯網
上載者:User

因為有些迷茫,所以準備直接上手項目

開始學習Python web驅動測試一書,沒想到一開始就發生了錯誤

環境是最新版的Python,Selenium,Firefox,Django等

按書上的代碼敲

from selenium import webdriverbrowser = webdriver.Firefox()browser.get('http://localhost:8000')assert 'Django' in browser.title


結果無情報錯


Traceback (most recent call last):  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 74, in start    stdout=self.log_file, stderr=self.log_file)  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__    restore_signals, start_new_session)  File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child    raise child_exception_type(errno_num, err_msg)FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'During handling of the above exception, another exception occurred:Traceback (most recent call last):  File "functional_test.py", line 2, in <module>    browser = webdriver.Firefox()  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 140, in __init__    self.service.start()  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 81, in start    os.path.basename(self.path), self.start_error_message)selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x7f3f272d3ac8>>Traceback (most recent call last):  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 173, in __del__    self.stop()  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 145, in stop    if self.process is None:


關鍵區段大概就是說我的什麼geckodriver各種不正確

沒有找到且未添加路徑什麼的

百度了一下發現也有很多人出現這樣的問題

瞭解了一下大概

geckodriver是Firefox的驅動
但網上的解決辦法大多是win的

stackoverflow上一個老外給出了降級的辦法解決,但降級總不是好辦法,於是繼續尋找

綜合來說解決辦法為,自行安裝geckodriver,並添加到相關路徑


於是到github (戳這裡)下載了Linux的geckodriver

然後進行相關操作

sudo tar zxvf geckodriver-v0.11.1-linux64.tar.gz #解壓sudo mv geckodriver /usr/bin/ #移動到指定路徑
cd /usr/bin/                    #進入路徑
sudo chmod +x geckodriver        #除去許可權


之後再次測試Python代碼,成功


有點小爽嘿嘿

解決辦法來自http://blog.csdn.net/heybob/article/details/52922645

感謝大神


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.