1

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?

Stephan
  • 75
  • 1
  • 9

2 Answers2

1

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

Željko Filipin
  • 56,372
  • 28
  • 94
  • 125
  • I just got this message today, odd because I use this method all the time. I think there is some bug in WATIR classic where this method becomes undefined on rare occasions. Probably some Windows issue that gives WATIR garbage from IE and WATIR isn't handling it properly? $browser.link(:text, /Next/).click ------------------ Watir::Exception::MissingWayOfFindingObjectException: text is an unknown way of finding a element ((?-mix:Next)) – Chad Brewbaker Dec 17 '13 at 19:03
0

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

b.link(:name => 'a_name').flash
halfelf
  • 9,737
  • 13
  • 54
  • 63
  • 1
    Thanks, however in Ruby 1.9 both notations are possible — and the one you gave yields the same exception, unfortunately. But have been a nice workaround, though. – Stephan Aug 22 '12 at 11:12