watir/watir_meta

Extending watir classes.

hemanth opened this issue · 4 comments

Let the code do the talking :

require 'watir'
module Watir
  class FieldElement < InputElement 
    # Some code 
  end 
end 

# Getting uninitilazed constant Watir::InputElement how come?

Same for :

require 'watir'

Watir.driver = :classic
Watir.load_driver

module Watir
  class FieldElement < InputElement 
    # Some code 
  end 
end 

Then, the below code works, after Watir::Browser.new module Watir will be loaded.

require 'watir'

browser = Watir::Browser.new

module Watir
  class FieldElement < InputElement 
    # Some code 
  end 
end 

So, is there a way to extend the class before Watir::Browser.new

The reason you're getting that error is because watir-classic has an autoload statement for IE class, which loads all the code. The code is actually rudimentary and from the times of FireWatir. It should be removed in the future, but currently you can do something like this if you're using only watir-classic:

require "watir"
Watir.driver = :classic
Watir.load_driver

# trigger autoload
Watir::IE

# your code

I've opened up a separate issue for removing autoload code watir/watir-classic#47

@jarmo Kool, was almost there, but had to do an Watir::IE will try it very soon and update.

Update : Super class mismatch for class UnknownObjectException and in irb undefined method driver for Watir:Module !

Oops, somehow i have missed your reply. Sorry about that.

If you're getting error like that then your monkey patch is wrong or you have loaded Watir-WebDriver. Can you show me your code?

Unable to find the code, but later on Watir.load_driver did work.