开发者

Does Watir recognize META HTML element?

开发者 https://www.devze.com 2023-01-11 03:59 出处:网络
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?

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?


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.


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\" />"


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

0

精彩评论

暂无评论...
验证码 换一张
取 消