Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting path to firefox binary on windows with selenium webdriver

Tags:

I am trying to build a utility function to output beautiful soup code to a browser I have the following code:

def bs4_to_browser(data):      from selenium import webdriver      driver = webdriver.Firefox(path="F:\FirefoxPortable\Firefox.exe")     driver.get("about:blank")      data = '<h1>test</h1>'  # supposed to come from BeautifulSoup     driver.execute_script('document.body.innerHTML = "{html}";'.format(html=data))      return 

when I run this I get:

TypeError at /providers/ __init__() got an unexpected keyword argument 'path' 

I am using win7. How to I set the path to the portable firefox executable?

like image 631
user1592380 Avatar asked Sep 07 '14 19:09

user1592380


People also ask

How do I set the path for Firefox drivers?

setproperty(“webdriver. gecko. driver”,Path_of_Firefox_Driver”); method to set the path of the Firefox Driver(GeckoDriver). Then it has created an object of Firefox Driver to instantiate the Mozilla Firefox browser and execute the test cases.

How do I use Firefox options in Selenium?

FirefoxOptions options = new FirefoxOptions(); driver = new RemoteWebDriver(new URL("http://10.x.x.x:4444/wd/hub"), options); When you start your Selenium Nodes, it displays a log information on using new FirefoxOptions preferred to 'DesiredCapabilities. firefox() along with all other browser options.

Which property should be set to run Firefox browser in Selenium?

Generally to run tests on our local machine, we will just specify as WebDriver driver = new FirefoxDriver(); to run on Firefox browser. System. setProperty("webdriver. gecko.


2 Answers

To set the custom path to Firefox you need to use FirefoxBinary:

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary  binary = FirefoxBinary('F:\FirefoxPortable\Firefox.exe') driver = webdriver.Firefox(firefox_binary=binary) 

Or, alternatively, add F:\FirefoxPortable to the PATH environment variable and fire up Firefox in a usual way:

driver = webdriver.Firefox() 
like image 89
alecxe Avatar answered Oct 11 '22 03:10

alecxe


By default selenium will look into the path - C:\Program Files (x86)\Mozilla Firefox\

Please install Firefox using the link - http://filehippo.com/download_firefox/67599/ and try

For this, you no need to give the binary.

If you want to install Firefox in custom location then give the directory as your wish when it pops up for location. If you installed in custom location then we need to mention Firefox binary location in the code as below

from selenium import webdriver from selenium.webdriver.firefox.firefox_binary import FirefoxBinary  binary = FirefoxBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe") fp = webdriver.FirefoxProfile() driver = webdriver.Firefox(firefox_binary=binary, firefox_profile=fp) 
like image 32
Karthikeya Avatar answered Oct 11 '22 03:10

Karthikeya