How to set custom firefox binary path node.js and selenium?

Viewed 1058

I just recently started trying out selenium and node.js, I have two Firefox versions installed, the normal (stable) and the developer edition, can you tell me how to make selenium web driver open up the normal Firefox instead of the developer edition one?

This is what I have tried in my .js file but I haven´t had any success, the Firefox with blue icon starts.

const webdriver = require('selenium-webdriver')
By = webdriver.By,
until = webdriver.until,
//var chrome = require('selenium-webdriver/chrome'),
firefox = require('selenium-webdriver/firefox');

//const mypath = new firefox.Options('C:\Program Files\Mozilla Firefox\firefox.exe');
//const firefoxOptions = new firefox.Options();

//----------------------------------------------------------------------------------

const myoptions =  new firefox.Options();
myoptions.setBinary('C:\Program Files\Mozilla Firefox\firefox.exe');

driver = new webdriver.Builder()
    .forBrowser('firefox ')
    //.setFirefoxOptions(myoptions)
    ///.setFirefoxOptions(
    ///new firefox.Options().setBinary('C:\ProgramFiles\MozillaFirefox\firefox.exe'))
    //.firefoxOptions(),
    .build();

driver.get('http://www.google.com');

...

I commented some lines as they give me errors.

Thanks in advance :)

1 Answers

the binary path string actually need 2 backslashes.

myoptions.setBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe');`

There also was a space to remove in forBrowser('firefox') in your code

Here is the final working code :

const webdriver = require('selenium-webdriver')
firefox = require('selenium-webdriver/firefox');

//----------------------------------------------------------------------------------

const myoptions =  new firefox.Options();
myoptions.setBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe');

driver = new webdriver.Builder()
    .forBrowser('firefox')
    .setFirefoxOptions(myoptions)
    .build();

driver.get('http://www.google.com');
Related