Monday, January 9, 2012

Adding Html tags to Watir libraries

Html tags to be verified in html page are maintained in non_control_elements.rb file in watir libraries under location Ruby location\lib\ruby\gems\1.9.1\gems\watir-2.0.4\lib.

If you have the framework for tags verification and some tags are not identified signifies that it is not there in non_control_elements. Here is the easy way to do it, just add below code to the end of this file

class LEGEND < NonControlElement
    TAG = 'LEGEND'
  end
  class TH < NonControlElement
    TAG = 'TH'
  end
  class BR < NonControlElement
    TAG = 'BR'
  end

With watir version 2.0.4 this has slightly changed and you need to do below:

%w[Pre P Div Span Map Area Li Ul H1 H2 H3 H4 H5 H6
     Dl Dt LEGEND TH TD Dd Strong Em Del Font Meta Ol].each do |elem|
    module_eval %Q{
      class #{elem} < NonControlElement; end
    }

This is it and you should be good to verify them in your framework. Hope it helps.