uploading local file into text_field using watir

M

michael

Could anybody help with the code below in Ruby / watir??

-------------------------------------------------------------------------------------------------------------------------------------------
require 'watir'

ie = Watir::IE.start("http://manymoandzo/cgi-bin/arp3/arp3.pl")

ie.text_field:)name, "name").set("user id")
ie.text_field:)name, "password").set("passwd")

ie.form:)name, "form").submit

ie =
Watir::IE.start("http://manymoandzo/cgi-bin/arp3/arp3.pl?a0=aut&a1=edi&a2=edi&mid=20")

$Path = "c:\test.htm"

ie.text_field:)name,'html_text').set($Path)
------------------------------------------------------------------------------------------------------------------------------------------
what I am struggling with is to insert whole content in test.htm to the
field 'html_text' in the web site..

this 'html_text' field is a big field, and I need to copy what is in
test.htm into 'html_text' field using watir.. I have about 600 of
these files.. which i would like to accomplish using watir..

but it never works out.. it is just writing... c:\test.htm in
'html_text' field, and what I want this watir program to do is to write
the text inside test.htm file in to the text_field, html_text.

i struggled so many hours.. and any help will be greatly appreciated.

thanks.

troubled michael..
 
M

Matt Todd

Well, what you're doing is just taking the contents of the variable
$Path and setting it to the text field. You'll actually need to open
and read the file. For example...

ie.text_field:)name, "html_text").set(File.new($Path).read)

That should do it.

M.T.
 
M

michael

Matt..

Thanks you so much.. It works beautifully..

Now as I have stated in my previous posting, I have many hundreds of
these files to upload..

the files are named as email1guide.htm, email2guide.htm..
email3guide.htm.. and so on.. like this..

Would you please tell me the way to iterate these postings in one
setting rather than doing one by one a couple of hundreds times??

thanks.


grateful, michael
 
M

Matt Todd

If you mean looping through them all, then you could just wrap it all
up in a little iteration block, like so:

1.upto(number_of_emails) do |num|
# your upload code
# use $Path = "c:\path\to\email#{num}guide.htm" to set the right name
end

Check out the documentation for Int and other enumerables if you're confused.

http://rubycentral.com/ref/ref_c_integer.html#upto

If you've not purchased it yet, do get Programming Ruby from the
Pragmatic Programmers. It's the definitive reference and learning
resource for Ruby. Plus, if you're feeling spunky enough, read _Why
The Lucky Stiff's Poignant Guide, http://www.poignantguide.net/ which
is a bit wacky, but is still an excellent introduction to the
language.

M.T.
 
M

michael

Matt..


do you know how to download pages through watir??

what would be the command for downloading web pages accessed through
Watir??

thanks.


michael
 
P

Patrick Spence

michael said:
Matt..

Thanks you so much.. It works beautifully..

Now as I have stated in my previous posting, I have many hundreds of
these files to upload..

the files are named as email1guide.htm, email2guide.htm..
email3guide.htm.. and so on.. like this..

Would you please tell me the way to iterate these postings in one
setting rather than doing one by one a couple of hundreds times??

thanks.


grateful, michael

#-- assuming all files you want to find start with "email" and have
#-- an ".htm" extension
files = Dir.glob("email*.htm")

#-- interate thru list of files
files.each {|file|

#-- this is where you'd do what you need with the file, for now
#-- we're just displaying the name of the file
puts(file)

}
 
M

michael

first of all, thank you for the suggestion..

now what if I wish to save the file in C:\ directory, with the file
name of 1.htm..

how do I change the code you have suggested?? what change do I make to
the code to save it as c:\1.htm??

thanks.

michael..
 
M

michael

first of all, thank you for the suggestion..

now what if I wish to save the file in C:\ directory, with the file
name of 1.htm..

how do I change the code you have suggested?? what change do I make to
the code to save it as c:\1.htm??

thanks.

michael..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top