Setting path to firefox binary on windows with selenium webdriver

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:FirefoxPortableFirefox.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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('F:FirefoxPortableFirefox.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()

Method 2

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)

Method 3

If you for example downloaded the chrome driver already, you can just specify the path to it like that:

from selenium import webdriver
driver = webdriver.Chrome(r'D:\chromedriver.exe')


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x