How to set path for Firefox Binary in Rails when using c9?

2.4k views Asked by At

For those who don't know, c9 is an online IDE that uses the cloud. So I’m trying to use FireFox with Watir and the error I’m getting is

"Could not find Firefox binary (os=linux). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path="

When I check the file path for FireFox on my PC it’s This PC/Windows(C:)/Program Files/Mozilla FireFox

This is my code which I am using

def save
    require 'watir'
    require 'firefox'

    @browser = Watir::Browser.new :firefox
    @browser.goto "https://kroger.softcoin.com/programs/kroger/digital_coupons/?origin=DigitalCoupons&banner=Smiths#contentBox"

    @browser.div(id: "contentBox").wait_until(&:present?).text

    # Could not find Firefox binary (os=linux). 
    # Make sure Firefox is installed or set the path manually with 
    # Selenium::WebDriver::Firefox::Binary.path=
    # ThisPC:WindowsC:ProgramFiles:MozillaFireFox

    @products = @browser.divs

end
1

There are 1 answers

2
Shubham Jain On

Try adding below code :

require 'selenium-webdriver'
Selenium::WebDriver::Firefox::Binary.path='C:/Program Files/Mozilla FireFox/firefox.exe'

Additionally you need to add geckodriver as higher version of firfox do not support without geckodriver

Download geckodriver from below URL :-

https://github.com/mozilla/geckodriver/releases

You also need to add path of geckodrover as below:

export PATH=$PATH:/path/to/geckodriver

refer :

https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver

Also refer :-

https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings

The java code which is working for me is as below:

System.setProperty("webdriver.gecko.driver", "C:\\abc\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://gmail.com");