Ruby selenium cannot load such file -- selenium-webdriver (LoadError)

Dimi picture Dimi · Apr 9, 2014 · Viewed 10.7k times · Source

I'm trying to utilize BrowserStack's automated testing using ruby with Selenium WebDriver with Eclipse.

Here is the code i'm trying to run:

require 'rubygems'
require 'selenium-webdriver'

# Input capabilities
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["browser"] = "IE"
caps["browser_version"] = "7.0"
caps["os"] = "Windows"
caps["os_version"] = "XP"
caps["browserstack.debug"] = "true"
caps[:name] = "Testing Selenium 2 with Ruby on BrowserStack"

driver = Selenium::WebDriver.for(:remote,
  :url => "http://xxxxxxxxxxxxx:[email protected]/wd/hub",
  :desired_capabilities => caps)
driver.navigate.to "http://www.google.com/ncr"
element = driver.find_element(:name, 'q')
element.send_keys "BrowserStack"
element.submit
puts driver.title

driver.quit

And here is the error i'm running into:

/Users/user/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- selenium-webdriver (LoadError)
from /Users/user/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/user/Documents/workspace/Lowfares/ie/wintest.rb:2:in `<main>'

Answer

houbena picture houbena · Oct 21, 2014

In my case it helped to add the following to my Gemfile

# in test group
gem 'selenium-webdriver'

Then run bundle install