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>'
In my case it helped to add the following to my gem file
gem 'selenium-webdriver
then run "bundle install"
What I realized is when you install selenium you need to run sudo gem install selenium-webdriver
for applications to access it.
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
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.
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 :-)
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:
- Installed Ruby with MSYS2 development tool chain option checked. Be default it is not checked.
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]
Checked Ruby SDK is selected. On Ruby-mine it is at Run->Edit Configuration
Installed the gem using:
gem install selenium-webdriver
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