【问题标题】:How to set path for Firefox Binary in Rails when using c9?使用 c9 时如何在 Rails 中设置 Firefox 二进制文件的路径?
【发布时间】:2018-02-21 16:27:55
【问题描述】:

对于那些不知道的人,c9 是一个使用云的在线 IDE。所以我尝试将 FireFox 与 Watir 一起使用,我得到的错误是

"找不到 Firefox 二进制文件 (os=linux)。确保 Firefox 是 手动安装或设置路径 Selenium::WebDriver::Firefox::Binary.path="

当我在我的电脑上检查 FireFox 的文件路径时,它是这台电脑/Windows(C:)/Program Files/Mozilla FireFox

这是我正在使用的代码

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

【问题讨论】:

  • 你用过geckodriver吗

标签: ruby-on-rails selenium firefox c9.io


【解决方案1】:

尝试添加以下代码:

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

另外你需要添加 geckodriver,因为更高版本的 firfox 不支持没有 geckodriver

从以下 URL 下载 geckodriver :-

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

你还需要添加geckodrover的路径,如下:

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

参考:

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

另请参考:-

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

对我有用的java代码如下:

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

【讨论】:

  • 收到错误“不是文件:“C:/Program Files/Mozilla FireFox/firefox.exe”。感谢您的回复。
  • 将您的 Firefox 安装在同一位置。你检查了吗? ..您使用的是我在回答中提到的 geckodriver 吗?
猜你喜欢
  • 2017-06-24
  • 2014-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多