Question

Context:

  • Win XP box, Ruby 1.9.2p290
  • gem list watir # => watir (3.0.0) watir-classic (3.1.0)
  • gem list sinatra # => sinatra (1.3.3)

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?

Was it helpful?

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

OTHER TIPS

I guess the parameter of link is not correct. Try this:

b.link(:name => 'a_name').flash
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top