您的位置:首页 > 其它

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

2017-03-19 22:20 1566 查看
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

First of all you will need to download latest executable geckodriver from here to run latest firefox
using selenium

Actually The Selenium client bindings tries to locate the 
geckodriver
 executable
from the system 
PATH
.
You will need to add the directory containing the executable to the system path.

On Unix systems you can do the following to append it to your system’s search path, if you’re using a bash-compatible shell:
export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step


On Windows you will need to update the Path system variable to add the full directory path to the executable geckodriver manually or command
line(don't forget to restart your system after adding executable geckodriver into system PATH to take effect). The principle is the same as on Unix.

Now you can run your code same as you're doing as below :-
from selenium import webdriver

browser = webdriver.Firefox()


selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line

Exception clearly states you have installed firefox some other location while Selenium is trying to find firefox and launch from default location but it couldn't find. You need to provide explicitly firefox installed binary location to launch firefox as below
:-
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('path/to/installed firefox binary')
browser = webdriver.Firefox(firefox_binary=binary)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐