You are still trying to attach to the page before it is opened.
1) Do not confuse the The Title TAG which is part of the page header
and sets the title of the webpage (which is usually displayed as the
title of the browser window) with a 'title' Attribute, which can be
set for any number of different tags within a page.. such 'title'
attributes apply only to the tag(s) within which they are defined, and
with respect to links have ZERO effect on the title of the page that
is loaded after the link is clicked. If you click a link and a new
page opens, that page will get its title from the title TAG in the
page header. Also link's need not have a title attribute defined, so
often it's not the best way to identify a link.
2) Attach does not click links, it does ONE thing and one thing only,
it attaches a browser object in your code to an active browser window
on the system. Period. For that to work the window has to exist,
FIRST before you invoke the attach function.
3) The code you provided below NEVER clicks a link, so no new page or
browser window is going to get loaded/created. All it does is check
for the presence of a link with a specific title attribute, it never
clicks that link.
4) Minor detail.. when writing in the Ruby language, most folks
reserve names like 'Browser' when defining a class, and use a
lowercase variable name 'browser' when creating an instance of the
class. I recommend observing that convention as it will make your
code less confusing to other folks who are used to seeing things done
that way.
SO in summary:
FIRST click the link, e.g.
browser.link(:text. 'New user').click
THEN after the clicking of that link has opened a new window, Attach
to the window e.g.
browser.attach(:title, '/Users: new/')
If it takes a bit of time for the new window to open, you might want
to put a short sleep between the two commands. (in general, the way
to know if that's needed is if it works fine done manually from an IRB
session, but fails when running your script.)
Try revising the code below to the above into account. If you are
still getting an error, provide the specific text of the error in
order to assist others in troubleshooting the problem with your code.
On Nov 30, 6:45 am, Amit Kulkarni amitkkulkarni...@gmail.com wrote:
Hi,
This is my code:
require 'rubygems'
require 'firewatir'
Watir::Browser.default = 'firefox'
Browser = Watir::Browser.new
Browser.goto(http://localhost:3000/users;) This goes to the
application
B = Browser.title.each { |d| puts d.to_s } here i am checking if
that page(above) contains any title.The ans is true and i am getting
Users:
a = Browser.link(:title, Users:).exist?
puts a
sleep 5
Browser.attach(:title, '/Users:/') On this i get an error i.e.
`attach': Unable to locate window, using title and /Users:/
(Watir::Exception::NoMatchingWindowFoundException)
Now if i try
Browser.attach(:title, Users:) --- No error is displayed and link is not
clicked.
--
Now the title on clicking the link is Users: which is same which i have
mentioned
I hope now the confusion is clear :)
Please let me know if you require any more info.
2010/11/30 Željko Filipin zeljko.fili...@wa-research.ch
On Tue, Nov 30, 2010 at 7:24 AM, Amit Kulkarni amitkkulkarni...@gmail.com
wrote:
titleUsers: new/title
titleUsers: index/title on the top
Browser.attach(:title, '/Users: new/')
I am now completely confused what is the title of the page that you want to
attach to. One of these could work:
Browser.attach(:title = Users: new/)
Browser.attach(:title = Users: index/)
Browser.attach(:title = /Users: new/)
Browser.attach(:title = /Users: index/)
Browser.attach(:title = /Users/)
More information:
http://wiki.openqa.org/display/WTR/New+Browser+Windows
Željko
--
Before posting, please readhttp://watir.com/support. In short: search
before you ask, be nice.
watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.comwatir-general%2bunsubscr...@googlegroups.com-
Hide quoted text -
- Show quoted text -
--
Before posting, please read http://watir.com/support. In short: search before
you ask, be nice.
watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com