I am a new user of Watir. I did not get the solution thread so posting
here:
This is a program to automate gmail to compose mail and check in the
sent item but it gives the following error :
>ruby autogmail.rb
Loaded suite autogmail
Started
E
Finished in 11.454 seconds.
1) Error:
test_gmaildemo(GmailDemo):
Watir::Exception::UnknownFrameException: Unable to locate a frame with
id canvas_frame
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/frame.rb:
40:in `locate'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/frame.rb:
47:in `initialize'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/container.rb:
102:in `new'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/container.rb:
102:in `frame'
autogmail.rb:13:in `test_gmaildemo'
1 tests, 0 assertions, 0 failures, 1 errors
>Exit code: 1
The original code is available in watir simple examples :
require 'test/unit'
require 'watir'
class GmailDemo < Test::Unit::TestCase
def test_gmaildemo
ie = Watir::IE.new
ie.goto('
mail.google.com')
ie.text_field(:name,'Email').set("
em...@gmail.com")
ie.text_field(:name,'Passwd').set("password")
ie.button(:name,'signIn').click_no_wait
# We need the iframe with ID 'canvas_frame'. Store it in a var.
canvas_frame = ie.frame(:id, 'canvas_frame')
# Get the current user's email address. We'll be sending email to
it.
my_address = canvas_frame.div(:id, 'guser').text.slice(/^.*@gmail
\.com/)
mail_subject = 'Hello Watir world!'
mail_body_text = 'Hi.'
canvas_frame.span(:text, 'Compose Mail').click # Compose new mail
canvas_frame.text_field(:name, 'to').set(my_address)
canvas_frame.text_field(:name, 'subject').set(mail_subject)
# The mail body field is contained in its own iframe, which only
contains
# a body element. So, save the iframe in a var, then set the
innerText
# property of the iframe's body element.
mail_body_frame = canvas_frame.frame(:index, 1)
# TODO: there must be a friendlier way to do this, while still
avoiding
# hardcoding of any unfriendly identifiers. Does Watir need a body
method?
mail_body_frame.document.body.setproperty('innerText',
mail_body_text)
canvas_frame.button(:text, 'Send').click # Send the message
canvas_frame.link(:text, 'Sent Mail').click # Browse to sent mail
page
assert(canvas_frame.contains_text('Hello Watir world!'))
canvas_frame.link(:text, /Inbox/).click # Return to the inbox
page
ie.close
end
end