Ruby on Rails cannot load such a file - selenium-webdriver Error

I am testing a selenium web relay with phantoms from Ruby on Rails. I am testing locally on my computer.

The following code works fine in my Ruby script test when I run "ruby test.rb"

def google_title require 'selenium-webdriver' driver = Selenium::WebDriver.for :phantomjs driver.navigate.to "https://www.google.com" page_title = driver.title puts page_title end google_title 

I have almost the same code in the application_controller.rb file:

  def google_title require 'selenium-webdriver' driver = Selenium::WebDriver.for :phantomjs driver.navigate.to "https://www.google.com" page_title = driver.title render text: page_title end 

But when I launch my application, I get the error message "I can’t download such a file - selenium-webdriver".

enter image description here

I added this to my Gemfile and installed the package, but I get the same error.

 gem 'selenium-webdriver', '~> 2.45' 

When I run the gem --local list, it shows that selenium is installed.

Any help would be appreciated.

Update:

I used almost the same code as above, but with watir-webdriver and got the same results. The Ruby script did a great job of this, but gave the error β€œcan't load such a file” for watir-webdriver when I tried to run it from Rails.

I ran another test with the nokogiri and it worked fine. Both he and Rails.

Update2:

I seem to be doing something, not my test environment. I just ran the same code in the online IDE and got the same type of errors:

enter image description here

Update3:

Here is the full content of the application_controller.rb file when I run the test using watir-webdriver and headless. I get the same results. Maybe I'm installing something wrong here?

 class ApplicationController < ActionController::Base def google_title require 'watir-webdriver' require 'headless' headless = Headless.new headless.start b = Watir::Browser.start 'www.google.com' page_title = b.title b.close headless.destroy render text: page_title end end 

enter image description here

+6
source share
1 answer

Have you restarted your webrick server, puma ...?

works like a charm.

gem 'selenium-webdriver', '~> 2.45'

bundle install

on mac:

brew install phantomjs

 class ApplicationController < ActionController::Base protect_from_forgery with: :exception #no need for require def google_title driver = Selenium::WebDriver.for :phantomjs driver.navigate.to "https://www.google.com" page_title = driver.title render text: page_title end end 

routes.rb:

get 'google-title' => 'application#google_title'

 http://127.0.0.1:3000/google-title 

google result

0
source

All Articles