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

11,908

Solution 1

What I realized is when you install selenium you need to run sudo gem install selenium-webdriver for applications to access it.

Solution 2

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

# in test group
gem 'selenium-webdriver'

Then run bundle install

Solution 3

This is because, the libraries are not installed globally

sudo gem install --no-user-install selenium-webdriver

the above command install the libs inside ruby-2.3.1@global

Image

Share:
11,908
Dimi
Author by

Dimi

Updated on June 18, 2022

Comments

  • Dimi
    Dimi about 2 years

    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>'
    
  • robdel12
    robdel12 about 3 years
    I know this is a really old post, but I just wanted to mention this is probably the right answer. It was the solve for me -- the other answers here require you to install the gem globally (rather than as a local dependency to the project). Globals are bad, imo. Anyways, cheers for this and take the upvote! Hopefully one day it won't be in the negatives
  • mattp
    mattp about 3 years
    I needed to do this and install the chromedriver binary into my path. (I downloaded from chromedriver.chromium.org)