5

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
Holger Just
  • 52,918
  • 14
  • 115
  • 123
khan
  • 547
  • 3
  • 18
  • can you do `gem list --local` and show the output here? – Arup Rakshit Oct 05 '13 at 16:28
  • D:\>gem list --local *** LOCAL GEMS *** bigdecimal (1.2.1, 1.1.0) childprocess (0.3.9) commonwatir(4.0.0) ffi(1.9.0 x86-mingw32) io-console(0.4.2, 0.3) json(1.8.0, 1.5.5) mini_portile(0.5.1) minitest(5.0.8, 2.5.1) multi_json(1.8.1) rake(10.1.0, 0.9.2.2) rdoc(4.0.1, 3.9.5) rubyzip(1.0.0, 0.9.9) selenium-webdriver (2.35.1) watir-webdriver (0.6.4) websocket(1.1.1, 1.0.7) win32-api 1.5.0 universal-mingw32) win32-process (0.7.3) windows-api(0.4.2) windows-pr(1.2.2) – khan Oct 05 '13 at 16:34
  • @khan did you install watir gem correctly? if you are getting same error with firefox . try to install watir gem again .try gem install watir --system – unknownbits Oct 05 '13 at 17:13
  • @prashantsharma why `gem install watir --system` is needed.. please don't advice him this... Let him understand how to use `watir-webdriver`.. – Arup Rakshit Oct 05 '13 at 17:16
  • It worked for me with firefox. – unknownbits Oct 05 '13 at 17:19
  • hey prashanth can u tell me like how to access the element on gmail(account create page ) which has Birthday (month) it tried with all the valid html elements but unable t o identify it – khan Oct 05 '13 at 17:35
  • please post new question for this . , I shall tell you then. – unknownbits Oct 05 '13 at 17:55
  • yaa i did that pleaase look into it – khan Oct 05 '13 at 18:04

3 Answers3

6

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.

Jarmo Pertman
  • 1,905
  • 1
  • 12
  • 19
  • 1
    when I say gem install watir I got the following error "unable to build native gem extension nmake is not recognized as internal or external command". – khan Jun 19 '14 at 16:57
1

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'
Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
  • D:\>irb irb(main):001:0> require 'watir-webdriver' => true irb(main):002:0> ie=Watir::IE.start 'www.gmail.com' NameError: uninitialized constant Watir::IE from (irb):2 from D:/Ruby193/bin/irb:12:in `
    ' irb(main):003:0> when i do that iget the above error
    – khan Oct 05 '13 at 16:46
  • @khan You are using `watir-webdriver` gem,not `watir`.. *Notice* that. – Arup Rakshit Oct 05 '13 at 16:48
  • so wat next i mean i can open the browser through webdriver – khan Oct 05 '13 at 16:51
  • 1
    browser=Watir::Browser.new :chrome even i tried with the baive statements but i get the error can u please help me out – khan Oct 05 '13 at 16:54
  • irb(main):004:0> browser=Watir::Browser.new :chrome Selenium::WebDriver::Error::WebDriverError: Unable to find the chromedriver exec utable. Please download the server from http://code.google.com/p/chromedriver/do wnloads/list and place it somewhere on your PATH. More info at http://code.googl e.com/p/selenium/wiki/ChromeDriver. from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/s elenium/webdriver/chrome/service.rb:20:in `executable_path' from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/chrome/service.rb:33:in `default_service' – khan Oct 05 '13 at 17:05
  • @khan do you have `firefox` ? Then try that.. for chrome and IE I think some extra installation you need to do.. – Arup Rakshit Oct 05 '13 at 17:06
  • @khan Did you try `b = Watir::Browser.new :firefox` ? It should work if you have installed `firefox`... – Arup Rakshit Oct 05 '13 at 17:09
  • @khan did you install watir gem correctly? if you are getting same error with firefox . try to install watir gem again .try gem install watir --system – unknownbits Oct 05 '13 at 17:12
  • @prashantsharma OP wanted to use `watir-webdriver`.. Don't make him confuse with the new gem.. :) to use `watir-webdriver`,`gem install watir-webdriver` enough.. – Arup Rakshit Oct 05 '13 at 17:13
  • thanks arup its working fine for firefox can u please tell me like what are the extra setings to be done for IE and CHROME – khan Oct 05 '13 at 17:16
  • @khan I would suggest you to go with `Firefox`,as it is cool. But if you want chrome,then here you get the file to [download](http://watirwebdriver.com/chrome/). – Arup Rakshit Oct 05 '13 at 17:18
  • one more question like without using watir-webdriver how can i navigate to browser using just Watir – khan Oct 05 '13 at 17:21
  • hey arup how can u tell me like how to access the link in gmail(account create page),which contains BIRTHDAY(month)i tried with all the possible and valid html elements – khan Oct 05 '13 at 17:25
  • hey can u please tell me how to accept the answer i started using it recently – khan Oct 05 '13 at 18:13
  • hey done arup i have accepted by the way what kind of benefit do u receive if i accept it ,do reply – khan Oct 05 '13 at 18:19
  • k cool thats great hey can u tell which command is used to maximize the browser – khan Oct 05 '13 at 18:34
0

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.