# Watir and Inheritance

**URL:** <https://rubytalk.org/t/watir-and-inheritance/41615>\
**Category:** ruby-talk\
**Created:** [23 October 2007 17:22 UTC](https://rubytalk.org/t/watir-and-inheritance/41615 "2007-10-23T17:22:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mario\_Ruiz1](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Mario\_Ruiz1](https://rubytalk.org/u/Mario_Ruiz1)\
**Post date:** [23 October 2007 17:22 UTC](https://rubytalk.org/t/watir-and-inheritance/41615/1 "2007-10-23T17:22:30Z")

</div>

I'm trying to do this:

> **···**
>
> -----------------------------  
> require 'Watir'
> 
> class Navigator\<Watir::IE  
> &nbsp;&nbsp;def initialize(maxim)  
> &nbsp;&nbsp;&nbsp;&nbsp;@maxim=maxim  
> &nbsp;&nbsp;&nbsp;&nbsp;@iex=Watir::IE.new  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;def go(url)  
> &nbsp;&nbsp;&nbsp;&nbsp;@iex.goto(url)  
> &nbsp;&nbsp;&nbsp;&nbsp;if @maxim==1 then  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@iex.maximize()  
> &nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;end  
> end
> 
> naveg=Navigator.new(1)  
> naveg.go("[http://www.google.es](http://www.google.es)")
> 
> puts naveg.url  
> --------------------------------  
> I want my 'naveg' object can display the methods and properties of  
> wakir, url for example. What am I doing wrong?  
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Kyle\_Schmitt](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@Kyle\_Schmitt](https://rubytalk.org/u/Kyle_Schmitt)\
**Post date:** [23 October 2007 17:30 UTC](https://rubytalk.org/t/watir-and-inheritance/41615/2 "2007-10-23T17:30:17Z")

</div>

Without looking at this too indepth...  
you are inheriting from Watir::IE, and then making a new instance of  
it inside of it? Ehh?

Start off with changing  
class Navigator\<Watir::IE  
to  
class Navigator

Now your class will work (but won't be inheriting). I don't know what  
you really want to do with your class 🙂 but hey, have fun playing  
with it!

--Kyle

> **···**
>
> On 10/23/07, Mario Ruiz \<tcblues@gmail.com\> wrote:
> 
> > I'm trying to do this:  
> > -----------------------------  
> > require 'Watir'
> > 
> > class Navigator\<Watir::IE  
> > &nbsp;&nbsp;def initialize(maxim)  
> > &nbsp;&nbsp;&nbsp;&nbsp;@maxim=maxim  
> > &nbsp;&nbsp;&nbsp;&nbsp;@iex=Watir::IE.new  
> > &nbsp;&nbsp;end  
> > &nbsp;&nbsp;def go(url)  
> > &nbsp;&nbsp;&nbsp;&nbsp;@iex.goto(url)  
> > &nbsp;&nbsp;&nbsp;&nbsp;if @maxim==1 then  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@iex.maximize()  
> > &nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;end  
> > end
> > 
> > naveg=Navigator.new(1)  
> > naveg.go("[http://www.google.es](http://www.google.es)")
> > 
> > puts naveg.url  
> > --------------------------------  
> > I want my 'naveg' object can display the methods and properties of  
> > wakir, url for example. What am I doing wrong?  
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Drew\_Olson](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@Drew\_Olson](https://rubytalk.org/u/Drew_Olson)\
**Post date:** [23 October 2007 17:36 UTC](https://rubytalk.org/t/watir-and-inheritance/41615/3 "2007-10-23T17:36:22Z")

</div>

Mario Ruiz wrote:

> I want my 'naveg' object can display the methods and properties of  
> wakir, url for example. What am I doing wrong?

You want to call the url method on the @iex object, not the navigator  
object. Try this:

require 'Watir'

class Navigator\<Watir::IE  
&nbsp;&nbsp;def method\_misssing(name,\*args)  
&nbsp;&nbsp;&nbsp;&nbsp;if @iex.respond\_to? name  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@iex.send(name,\*args)  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
&nbsp;&nbsp;def initialize(maxim)  
&nbsp;&nbsp;&nbsp;&nbsp;@maxim=maxim  
&nbsp;&nbsp;&nbsp;&nbsp;@iex=Watir::IE.new  
&nbsp;&nbsp;end  
&nbsp;&nbsp;def go(url)  
&nbsp;&nbsp;&nbsp;&nbsp;@iex.goto(url)  
&nbsp;&nbsp;&nbsp;&nbsp;if @maxim==1 then  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@iex.maximize()  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
end

naveg=Navigator.new(1)  
naveg.go("[http://www.google.es](http://www.google.es)")

puts naveg.url

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Jesus\_Gabriel\_y\_Gala](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@Jesus\_Gabriel\_y\_Gala](https://rubytalk.org/u/Jesus_Gabriel_y_Gala)\
**Post date:** [24 October 2007 09:37 UTC](https://rubytalk.org/t/watir-and-inheritance/41615/4 "2007-10-24T09:37:48Z")

</div>

I think what you are doing wrong is having a Watir::IE object inside  
your Navigator class. If you inherit from IE you have all methods in  
IE available so you don't need to wrap another instance of IE inside.  
Can you try this (not tested):

require 'Watir'

class Navigator\<Watir::IE  
def initialize(maxim)  
&nbsp;&nbsp;&nbsp;@maxim=maxim  
end  
def go(url)  
&nbsp;&nbsp;&nbsp;goto(url)  
&nbsp;&nbsp;&nbsp;if @maxim==1 then  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maximize()  
&nbsp;&nbsp;&nbsp;end  
end  
end

naveg=Navigator.new(1)  
naveg.go("[http://www.google.es](http://www.google.es)")

puts naveg.url

Hope this helps,

Jesus.

> **···**
>
> On 10/23/07, Mario Ruiz \<tcblues@gmail.com\> wrote:
> 
> > I'm trying to do this:  
> > -----------------------------  
> > require 'Watir'
> > 
> > class Navigator\<Watir::IE  
> > &nbsp;&nbsp;def initialize(maxim)  
> > &nbsp;&nbsp;&nbsp;&nbsp;@maxim=maxim  
> > &nbsp;&nbsp;&nbsp;&nbsp;@iex=Watir::IE.new  
> > &nbsp;&nbsp;end  
> > &nbsp;&nbsp;def go(url)  
> > &nbsp;&nbsp;&nbsp;&nbsp;@iex.goto(url)  
> > &nbsp;&nbsp;&nbsp;&nbsp;if @maxim==1 then  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@iex.maximize()  
> > &nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;end  
> > end
> > 
> > naveg=Navigator.new(1)  
> > naveg.go("[http://www.google.es](http://www.google.es)")
> > 
> > puts naveg.url  
> > --------------------------------  
> > I want my 'naveg' object can display the methods and properties of  
> > wakir, url for example. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![Mario\_Ruiz](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@Mario\_Ruiz](https://rubytalk.org/u/Mario_Ruiz)\
**Post date:** [24 October 2007 09:29 UTC](https://rubytalk.org/t/watir-and-inheritance/41615/5 "2007-10-24T09:29:44Z")

</div>

If I write the class without inheriting, how can I get the 'url' outside  
of the class?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Mario\_Ruiz](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@Mario\_Ruiz](https://rubytalk.org/u/Mario_Ruiz)\
**Post date:** [24 October 2007 09:31 UTC](https://rubytalk.org/t/watir-and-inheritance/41615/6 "2007-10-24T09:31:16Z")

</div>

Drew Olson wrote:

> You want to call the url method on the @iex object, not the navigator  
> object. Try this:

...

This is not working.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Mario\_Ruiz](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@Mario\_Ruiz](https://rubytalk.org/u/Mario_Ruiz)\
**Post date:** [24 October 2007 09:42 UTC](https://rubytalk.org/t/watir-and-inheritance/41615/7 "2007-10-24T09:42:21Z")

</div>

Jesús Gabriel y Galán wrote:...

I'm sorry but it doesn't work because the class doesn't understand the  
IE methods without the suffix.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Kyle\_Schmitt](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@Kyle\_Schmitt](https://rubytalk.org/u/Kyle_Schmitt)\
**Post date:** [24 October 2007 12:45 UTC](https://rubytalk.org/t/watir-and-inheritance/41615/8 "2007-10-24T12:45:16Z")

</div>

Watir's ie object allows you to get at things like the url using  
public methods. Unless the idea really is extending or or replacing  
them, inheritance shouldn't be necessary (or probably advised). Well,  
that is unless the whole point is to play around with Watir to learn  
about it, more than get work done 😉

> **···**
>
> On 10/24/07, Jesús Gabriel y Galán \<jgabrielygalan@gmail.com\> wrote:
> 
> > On 10/23/07, Mario Ruiz \<tcblues@gmail.com\> wrote:  
> > \> I'm trying to do this:  
> > \> -----------------------------  
> > \> require 'Watir'  
> > \>  
> > \> class Navigator\<Watir::IE  
> > \> def initialize(maxim)  
> > \> @maxim=maxim  
> > \> @iex=Watir::IE.new  
> > \> end  
> > \> def go(url)  
> > \> @iex.goto(url)  
> > \> if @maxim==1 then  
> > \> @iex.maximize()  
> > \> end  
> > \> end  
> > \> end  
> > \>  
> > \> naveg=Navigator.new(1)  
> > \> naveg.go("[http://www.google.es](http://www.google.es)")  
> > \>  
> > \> puts naveg.url  
> > \> --------------------------------  
> > \> I want my 'naveg' object can display the methods and properties of  
> > \> wakir, url for example. What am I doing wrong?
> > 
> > I think what you are doing wrong is having a Watir::IE object inside  
> > your Navigator class. If you inherit from IE you have all methods in  
> > IE available so you don't need to wrap another instance of IE inside.  
> > Can you try this (not tested):
> > 
> > require 'Watir'
> > 
> > class Navigator\<Watir::IE  
> > def initialize(maxim)  
> > &nbsp;&nbsp;&nbsp;@maxim=maxim  
> > end  
> > def go(url)  
> > &nbsp;&nbsp;&nbsp;goto(url)  
> > &nbsp;&nbsp;&nbsp;if @maxim==1 then  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maximize()  
> > &nbsp;&nbsp;&nbsp;end  
> > end  
> > end
> > 
> > naveg=Navigator.new(1)  
> > naveg.go("[http://www.google.es](http://www.google.es)")
> > 
> > puts naveg.url
> > 
> > Hope this helps,
> > 
> > Jesus.

---

<div class="post-metadata">

**Author:** ![Mario\_Ruiz](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@Mario\_Ruiz](https://rubytalk.org/u/Mario_Ruiz)\
**Post date:** [24 October 2007 10:15 UTC](https://rubytalk.org/t/watir-and-inheritance/41615/9 "2007-10-24T10:15:05Z")

</div>

By the way the error is:  
c:/ruby/lib/ruby/site\_ruby/1.8/Watir.rb:1341:in `url': undefined method  
`LocationURL' for nil:NilClass (NoMethodError)  
&nbsp;&nbsp;from tempexample.rb:22

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Rubenson\_Crusoe](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@Rubenson\_Crusoe](https://rubytalk.org/u/Rubenson_Crusoe)\
**Post date:** [24 October 2007 13:25 UTC](https://rubytalk.org/t/watir-and-inheritance/41615/10 "2007-10-24T13:25:19Z")

</div>

I think Jesus' approach is correct. It only missed the initialization of the  
super class:

class Navigator\<Watir::IE  
def initialize(maxim)  
&nbsp;&nbsp;super()  
&nbsp;&nbsp;@maxim=maxim  
end  
def go(url)  
&nbsp;&nbsp;goto(url)  
&nbsp;&nbsp;if @maxim==1 then  
&nbsp;&nbsp;&nbsp;&nbsp;maximize()  
&nbsp;&nbsp;end  
end  
end

At first I thought calling 'super' would do but then I was pointed out by  
him that 'super' calls the superclass' initialize method with the same  
number of parameters, so we need parenthesis (good to know 🙂

Anyway with 'super()' it seems it works:

naveg=Navigator.new(1)  
naveg.go("[http://www.google.es](http://www.google.es)")

puts naveg.url # =\> =\> "[http://www.google.es/&quot](http://www.google.es/&quot);

/Rubén

> **···**
>
> On 10/24/07, Kyle Schmitt \<kyleaschmitt@gmail.com\> wrote:
> 
> > Watir's ie object allows you to get at things like the url using  
> > public methods. Unless the idea really is extending or or replacing  
> > them, inheritance shouldn't be necessary (or probably advised). Well,  
> > that is unless the whole point is to play around with Watir to learn  
> > about it, more than get work done 😉
> > 
> > On 10/24/07, Jesús Gabriel y Galán \<jgabrielygalan@gmail.com\> wrote:  
> > \> On 10/23/07, Mario Ruiz \<tcblues@gmail.com\> wrote:  
> > \> \> I'm trying to do this:  
> > \> \> -----------------------------  
> > \> \> require 'Watir'  
> > \> \>  
> > \> \> class Navigator\<Watir::IE  
> > \> \> def initialize(maxim)  
> > \> \> @maxim=maxim  
> > \> \> @iex=Watir::IE.new  
> > \> \> end  
> > \> \> def go(url)  
> > \> \> @iex.goto(url)  
> > \> \> if @maxim==1 then  
> > \> \> @iex.maximize()  
> > \> \> end  
> > \> \> end  
> > \> \> end  
> > \> \>  
> > \> \> naveg=Navigator.new(1)  
> > \> \> naveg.go("[http://www.google.es](http://www.google.es)")  
> > \> \>  
> > \> \> puts naveg.url  
> > \> \> --------------------------------  
> > \> \> I want my 'naveg' object can display the methods and properties of  
> > \> \> wakir, url for example. What am I doing wrong?  
> > \>  
> > \> I think what you are doing wrong is having a Watir::IE object inside  
> > \> your Navigator class. If you inherit from IE you have all methods in  
> > \> IE available so you don't need to wrap another instance of IE inside.  
> > \> Can you try this (not tested):  
> > \>  
> > \> require 'Watir'  
> > \>  
> > \> class Navigator\<Watir::IE  
> > \> def initialize(maxim)  
> > \> @maxim=maxim  
> > \> end  
> > \> def go(url)  
> > \> goto(url)  
> > \> if @maxim==1 then  
> > \> maximize()  
> > \> end  
> > \> end  
> > \> end  
> > \>  
> > \> naveg=Navigator.new(1)  
> > \> naveg.go("[http://www.google.es](http://www.google.es)")  
> > \>  
> > \> puts naveg.url  
> > \>  
> > \> Hope this helps,  
> > \>  
> > \> Jesus.  
> > \>  
> > \>

---

<div class="post-metadata">

**Author:** ![Mario\_Ruiz](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@Mario\_Ruiz](https://rubytalk.org/u/Mario_Ruiz)\
**Post date:** [24 October 2007 14:42 UTC](https://rubytalk.org/t/watir-and-inheritance/41615/11 "2007-10-24T14:42:24Z")

</div>

Now it works fine.

Thank you very much.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
