rubywatirname-attribute

How to find a HTML link using Watir (3.0) and the name attribute


Context:

Given a rather simplistic web site as this:

require "sinatra"
get '/' do
    "<a href='http://example.com/' name='a_name' >Click me!</a>"
end

When I run the sinatra app on the default port (4567) and…

Then, in a command line, I try to use the link via the name attribute I get an exception:

j:…>pry -r watir
[1] pry(main)> b = Watir::Browser.new
=> #<Watir::IE:0x1538fd32 url="about:blank" title="">
[2] pry(main)> b.goto "http://localhost:4567/"
=> 0.203129
[3] pry(main)> b.link( name: 'a_name' ).flash
Watir::Exception::MissingWayOfFindingObjectException: name is an unknown way of finding a <a> element (a_name)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-classic/locator.rb:76:in `rescue in match?'

Am I doing it wrong? On other HTML elements searching by name still works fine. Up to now the previous Watir versions worked fine as well. What am I missing? Or is using the name attribute not supported anymore?


Solution

  • Since the error message says name is an unknown way of finding a <a> element, I guess name attribute is not longer supported for links. That looks like a bug to me, since as far as I can see name attribute is still supported for links: http://www.w3.org/TR/html401/struct/links.html

    You can report the bug here: https://github.com/watir/watir-classic/issues