'ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- selenium-webdriver (LoadError)

I am trying to run this below code, then I got code error:

ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- selenium-webdriver (LoadError)

I am not able to find what I am missing please help me with this

require "selenium-webdriver"

# Firefox browser instantiation
driver = Selenium::WebDriver.for :firefox

#Loading the assertselenium URL
driver.navigate.to "http://www.assertselenium.com"

#Clicking on the Follow link present on the assertselenium home page
FollowButton  = driver.find_element(:link, "Follow")
FollowButton.click

#Typing the UserName
LoginButton = driver.find_element(:id, "user_login")
LoginButton.send_keys "sampleuser77dff27"

#Typing the Email-Id
EmailId = driver.find_element(:id, "user_email")
EmailId.send_keys "[email protected]"

#Clicking on the Submit Button
SubmitButton = driver.find_element(:id, "wp-submit")
SubmitButton.click

#Asserting whether the registration success message is diaplyed
SuccessMessage = driver.find_element(:css, "p.message")
"Registration complete. Please check your e-mail.".eql? SuccessMessage.text
puts "Successfully completed the user registration and validated the Success message"
#Quitting the browser
driver.quit


Solution 1:[1]

Try add:

require 'rubygems'

on top of this script. If you still get the same error, then install the gem:

gem install selenium-webdriver

Hope it helps.

Solution 2:[2]

I resolved that issue, but my condition in that time was the project didn't run any command related to install or update gems, and throw a message complain me to update new version of an installed gem (sprockets). So, next are the steps I followed:

  1. Uninstall bundler with the actual version that ruby you are using by using: gem uninstall bundler

  2. Install bundler, this will make install the newest version bundler, using : gem install bundler

  3. Update all your installed gems of the project by using: bundle update

  4. And for just in case: bundle install

Solution 3:[3]

I had opened multiple projects when I got "Kernel-require" error. Then I opened my project in a separate window and I used the require statement again. It worked for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yunwei.W
Solution 2 Sebastian D'Agostino
Solution 3 Ruby_Learner