11

I'm trying to run the example scirpt of Selenium with Ruby on Rails. I've to run it with a proxy. Here's my code:

require 'rubygems'
require 'bundler/setup'

# require your gems as usual
require "selenium-webdriver"

Selenium::WebDriver::Firefox.path = "/home/marc/Documents/firefox/firefox"
profile = Selenium::WebDriver::Firefox::Profile.new
proxy = Selenium::WebDriver::Proxy.new(:http => nil)
profile.proxy = proxy
driver = Selenium::WebDriver.for :firefox, :profile => profile
driver.navigate.to "http://google.com"

element = driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver!"
element.submit

puts driver.title

driver.quit

I got the following error:

/home/marc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.0.0.beta3.1/lib/selenium/webdriver/common/service.rb:115:in `connect_until_stable': unable to connect to Mozilla geckodriver 127.0.0.1:4445 (Selenium::WebDriver::Error::WebDriverError)

Can someone help me...? I'm trying since hours and can't find the problem... Really don't know what to do.

Environment:

Ubuntu 16.04 LTS, Firefox 45.0, rbenv 2.3.1

Other question: Someone knows some example for Selenium + Ruby on Rails? I can't find really good stuff... the documentation is really poor :(

rj487
  • 4,476
  • 6
  • 47
  • 88
Twinfriends
  • 1,972
  • 1
  • 14
  • 34

3 Answers3

9

You have selenium-webdriver-3.0.0.beta3.1 which is only for Firefox 48 and later (and not yet properly working). Fallback to selenium-webdriver version 2.53.4 and try again.

DarKy
  • 153
  • 4
  • 9
  • Thanks, i got the solution yesterday by myself. But it was exactly my problem, so you were 100 % right. – Twinfriends Sep 27 '16 at 13:29
  • thanks. i was trying to downgrade firefox and install gecko drivers and it didnt work. i just added "gem 'selenium-webdriver', '2.53.4'" and ran bundle update selenium-webdriver, and it works again. – appleLover Nov 18 '16 at 16:10
  • 1
    the problem is that newer versions of selenium (> 3.0) are not compatible with the older versions of Firefox (< 48). – Corey Goldberg Feb 23 '17 at 15:13
4

As an addition to DarKy's solution with selenium version downgrade:

  • In the terminal change directory path to the directory where gem was installed
  • Run gem uninstall selenium-webdriver
  • Run gem install selenium-webdriver -v 2.53.4
Andrii Vasyliev
  • 107
  • 1
  • 3
1
  • ruby: ruby 2.3.3p222
  • selenium-webdriver: selenium-webdriver (3.7.0)
  • Firefox : V57

Selenium::WebDriver::Firefox.driver_path = "â€ĒC:\\Users\\Desktop\\geckodriver.exe"
capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
driver = Selenium::WebDriver.for :firefox, desired_capabilities: capabilities
driver.navigate.to "https://google.com"
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Anil
  • 21
  • 3