I am attempting to properly install and run a Ruby script.

I have not worked in Ruby for some time and am not sure what I'm missing; it worked perfectly in the past (on a work machine.)

I am receiving the following error message:

<Main> undefined local variable or method ''watir'' for main: Object <NameError>

I have reserached this, but am unable to determine what is causing this error.

Version: ruby 2.2.6p396


require ‘watir’ 
require ‘watir-webdriver’
Watir::Browser.default = “firefox” 
browser = Watir::Browser.start  "https://www.website.com"
browser.link(:text, "Register").click
browser.button(:value,"I Agree").click
browser.button(:value,"I Agree").click
browser.text_field(:id, "username").set("bbb")
browser.text_field(:id, "password").set("bbb")
browser.text_field(:id, "password2").set("ccc")
browser.text_field(:id, "email").set("hhh")
browser.text_field(:id, "email2").set("yyy")
browser.checkbox(:name, "imagestring").set
browser.checkbox(:id, "emailpmnotify").set
browser.checkbox(:id, "invisible").set
browser.select_list(:id, "subscriptionmethod").select("No email notification")
browser.select_list(:id, "timezoneoffset").select("GMT -3:30 (06:27 PM)")
browser.select_list(:name, "dstcorrection").select("Never use DST correction")
browser.select_list(:id, "language").select("English (American)")
browser.button(:value,"Submit Registration!").click


Thank you in advance

5 Months
Discussion Span
Last Post by pty

My first checks would be to read a few priors at https://www.google.com/search?q=require+‘watir

This tells me that more work is required to get your watir working. You write you researched this but didn't share your research method. I don't have a Ruby setup today so it may be a while till I can try your code.

Edited by rproffitt: Clarifying



Thank you for your reply.

Research method entailed reading Ruby docs, searching for info regarding the error message, Ruby groups, etc.

All the info I found was quite vague.

Edited by mattyd: sp


I installed Watir yesterday.

The docs seem a bit unclear as to what gems are exactly needed to get this to work.

I used this a number of years ago at a QA job. All testing we did was manual (at that point) and we used Ruby/Watir to essentially simplify a few set-up steps for our tests. It worked wonderful.

Thank you for your help. I appreciate it.


I see I asked about your install method and I used that to see what's up. It appears the setup was more than you wrote about.

Let's try again tomorrow. I have a clean Windows 10 PC that I can test this on late tomorrow. I need your install method so I can check it out.


The problem looks like it's the quote symbol on your require line, require ‘watir’.

In Ruby, this needs to be either a standard ' or " pairing. If you really want to you can use percent string syntax, in therequire %q{watir} style, but in more than 14 years of Ruby I have never seen that syntax used in a require statement.

In short, you'll have more luck with require 'watir'.

Edited by pty

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.