Question

I'm running into the following error:

#ERROR
C:\Users\Farooq>D:

D:\>irb
irb(main):001:0> require 'rubygems'

=> false

irb(main):002:0> require 'watir'

LoadError: cannot load such file -- watir/loader
        from D:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from D:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/commonwatir-4.0.0/lib/watir.rb:1:in `<top (required)>'
        from D:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
        from D:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
        from D:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
        from (irb):2
        from D:/Ruby193/bin/irb:12:in `<main>'
irb(main):003:0>

I have installed the gem watir and my system configurations are as follows:

  • OS:Windows7
  • IE:10
Was it helpful?

Solution 2

Okay! so looking at the output of gem list --local I can surely tell you that you installed watir-webdriver,not the watir gem.

You should write it as require 'watir-webdriver'. You also don't need to require 'rubygems',as you are in Ruby1.9.3.

Here is a simple code using chrome:

require 'watir-webdriver'
b = Watir::Browser.new :chrome
b.goto 'https://www.google.co.in/'
b.text_field(:id => 'gbqfq').set 'ruby'

OTHER TIPS

Make sure watir gem is installed correctly. You can do it like this:

gem install watir

Ignore the other answers here which say that you should not install watir - it is perfectly normal to install watir since this is a meta gem, which will load watir-webdriver or watir-classic as needed.

And then in your code, do like this:

require "watir"

b = Watir::Browser.new :chrome # loads watir-webdriver and opens up a Chrome browser

However, if you do not specify the browser, then default will be used for current platform.

# on Windows
b = Watir::Browser.new # loads watir-classic and opens up an IE browser

# on unix
b = Watir::Browser.new # loads watir-webdriver and opens up a Firefox browser

In other words - using a watir gem is perfectly normal even if you'd like to use watir-webdriver underneath it because you can switch the drivers really easily.

You can read more from the watir readme.

got the same issue, what i did was clean all gems beside the default gem come with ruby by running "gem uninstall --all " and run "bundle install" using gemfile.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top