tags:

views:

87

answers:

3

Hi for SEO purpose we need to access META tags on the html pages. But Watir does not to support META tag. Is there any other way to access not supported HTML tags?

Any help appreciated.

Hi I found the way to access the elemnts by using getElementsTagByName b.document.getElementsByTagName('meta')[1].content test.rb:14:in `[]': can't convert Fixnum into String (TypeError)

Can you help with this?

A: 

Looks like Watir can not access meta tag: meta tag not implemented. You can vote for the ticket, or comment it.

Željko Filipin
A: 

Looks like watir-webdriver can access meta tags:

require "watir-webdriver"
#=> true
browser = Watir::Browser.start "google.com"
browser.meta(:index => 0).html
#=> "<meta xmlns=\"http://www.w3.org/1999/xhtml\" content=\"text/html; charset=UTF-8\" http-equiv=\"content-type\" />"
Željko Filipin
I tried using the above solution but it still gives me error : undefined method `meta' for #<Watir::IE:0x3d5ecf8> (NoMethodError)
QA tester
Actually I forgot to include webdriver, but now it is unable to find that filec:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- watir-webdriver (LoadError) from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
QA tester
c:/ruby/lib/ruby/gems/1.8/gems/watir-webdriver-0.0.6/lib/watir-webdriver/exception.rb:8: superclass mismatch for class UnknownObjectException (TypeError)from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from c:/ruby/lib/ruby/gems/1.8/gems/watir-webdriver-0.0.6/lib/watir-webdriver.rb:6 from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require' from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'from Live365.rb:2
QA tester
Did you install watir-webdriver gem? :) http://zeljkofilipin.com/2010/01/12/watir-on-webdriver/
Željko Filipin
Yes I did install it and it was installed successfully.
QA tester
I removed require watir statement and it worked. Thanks a lot.
QA tester
@QA tester: and where did you see in my code `require "watir"`? :) Yes, you should not require both watir and watir-webdriver at the same time.
Željko Filipin
By the way, it is a custom here to upvote the answer that helped you, and to accept the answer that solved your problem. Just saying. :)
Željko Filipin
Hi , I tried adding vote but it but gives me message it needs 15 reputation :(.I did accept the answer and thanking you again.
QA tester
+1  A: 

If you're using 'regular' Watir, you can find the meta tags in the html source.

It will depend on which browser you're using, but it will be something like this:

@browser.html #Internet explorer @browser.xml #celerity @browser.html #Firefox

You could then use HPricot or an XML parser to get the meta tags

require 'watir'
require 'hpricot'

$b=IE.start('http://www.google.com')
doc=Hpricot($b.html)
(doc/"meta").each { | tag | puts tag }

This works for me in IE and Firefox.

JaredQ
Hi, since the above solution works for document.body meta tags not returned. But it is great way to access other tags for which access methods not defined in Watir. Thanks
QA tester
Thanks for the solution it works.
QA tester