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

点点圈 提交于 2020-01-13 04:29:32

问题


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:xxxxxxxxxxxxxx@hub.browserstack.com/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>'

回答1:


In my case it helped to add the following to my gem file

gem 'selenium-webdriver

then run "bundle install"




回答2:


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




回答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




回答4:


I faced the same error when I used Sublime Text 2 and tried to run using the 'build' button. But the script ran fine when i ran it from the command prompt.

It has more to do with the path assigned to the editor more than anything else. ALthough do a quick a check on your gem list to see if the selenium - webdriver exists there or not.




回答5:


I had the same issue when changing laptop.

For me this was the path. In eclipse: Select 'Window' then 'Preferences' then select 'Ruby' and 'Interpreters' Ensure the interpreter selected points to your installation .exe of ruby

You could do a search or just browse to the path if you know it.

Once I fixed this I was up and running :-)




回答6:


In my case i was facing multiple such errors including cannot load such file — selenium-webdriver (LoadError). After installing Ruby dev kit with MSYS2 development tool chain the issue was resolved. Following were the steps followed:

  1. Installed Ruby with MSYS2 development tool chain option checked. Be default it is not checked.

  1. Ran all three MSYS2 installations one by one in order

    1 - MSYS2 base installation

    2 - MSYS2 system update (optional)

    3 - MSYS2 and MINGW development toolchain

Which components shall be installed? If unsure press ENTER [1,2,3]

  1. Checked Ruby SDK is selected. On Ruby-mine it is at Run->Edit Configuration

  2. Installed the gem using: gem install selenium-webdriver




回答7:


In my case, I was using Bundler, so simply adding require bundler/setup to the top fixed the problem for me. Hope that helps someone else.



来源:https://stackoverflow.com/questions/22952022/ruby-selenium-cannot-load-such-file-selenium-webdriver-loaderror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!