Python:selenium 模塊 webdriver使用報錯:No such file or directory: 'geckodriver': 'geckodriver'
1.例子:獲取網頁句柄
from selenium import webdriver
from time import sleep
browser=webdriver.Firefox()
browser.implicitly_wait(10)
browser.get("http://www.baidu.com")
#獲得百度搜索窗口句柄
handle=browser.current_window_handle
print(handle)
運行時,報錯:No such file or directory: 'geckodriver': 'geckodriver'
原因:Selenium是Python下一個Web應用程序測試工具,直接運行在瀏覽器中,支持IE、火狐等。安裝完Selenium之後,需要針對不同的瀏覽器安裝驅動,其中firefox需要的就是geckodriver,Chrome需要的是chromedriver。
2.解決:下載驅動,解壓後得到的是一個exe文件,將其放到/usr/local/bin下即可(Mac下)
geckodriver下載地址:https://github.com/mozilla/geckodriver/releases
chromedriver下載地址:http://chromedriver.storage.googleapis.com/index.html
下載chromedriver時,先進入查看最新版本,在進入對應版本下載