I am trying to open Firefox with selenium,i tried
from selenium import webdriver
driver=webdriver.Firefox()
But i got the following error:
selenium.common.exceptions.WebDriverException: Message: 'firefox' executable needs to be in PATH.
Selenium using Python - Geckodriver executable needs to be in PATH
I tried
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('/usr/bin/firefox')
browser = webdriver.Firefox(firefox_binary=binary)
Also tried
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX
caps['marionette'] = True
caps['binary'] = '/usr/bin/firefox'
d = webdriver.Firefox(capabilities=caps)
`but still did not work.
However, when i tried using the above code replacing the last line with
d=webdriver.Firefox(capabilities=caps,executable_path='/usr/bin/firefox')
and having my Firefox closed from background it would open Firefox but I can't simply d.get("https://www.google.com")
it gets stuck on Linux homepage and doesn't open anything.
After typing whereis firefox
in terminal i got /usr/bin/firefox
,also if it matters i use python 2.7
Note : I hope this isn't a duplicate of the above link because i tried the answers and it didn't fix it.
I installed geckodriver from github , and tried browser=webdriver.Firefox(executable_path="geckodriver")
,I have placed the driver is the same directory.
It is still not clear why you are seeing the error as:
selenium.common.exceptions.WebDriverException: Message: 'firefox' executable needs to be in PATH.
In majority of the cases the common PATH related error is associated with geckodriver .
However, while working with Selenium 3.x you need to download the latest GeckoDriver from mozilla/geckodriver and save it anywhere in your system and provide the absolute path of the GeckoDriver through the argument executable_path
.
The following code block works perfecto to open Firefox Nightly Browser (installed at customized location):
Code Block:
from selenium import webdriver from selenium.webdriver.firefox.options import Options options = Options() options.binary_location = '/path/to/firefox' driver = webdriver.Firefox(firefox_options=options, executable_path='/path/to/geckodriver') driver.get('http://google.com/') print("Page title is: %s" %(driver.title)) driver.quit()
Console Output:
Page title is: Google
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.