[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

uploading local file into text_field using watir

michael

8/5/2006 7:50:00 PM

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..

7 Answers

Matt Todd

8/5/2006 8:12:00 PM

0

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.

michael

8/5/2006 10:32:00 PM

0

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


Matt Todd wrote:
> 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.

Matt Todd

8/6/2006 1:59:00 AM

0

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...

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.poignant... which
is a bit wacky, but is still an excellent introduction to the
language.

M.T.

michael

8/8/2006 4:31:00 PM

0

Matt..


do you know how to download pages through watir??

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

thanks.


michael

Matt Todd wrote:
> 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...
>
> 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.poignant... which
> is a bit wacky, but is still an excellent introduction to the
> language.
>
> M.T.

Patrick Spence

8/9/2006 1:25:00 PM

0

michael wrote:
> 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)

}


--
Posted via http://www.ruby-....

michael

8/9/2006 2:06:00 PM

0

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..


Patrick Spence wrote:
> michael wrote:
> > 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)
>
> }
>
>
> --
> Posted via http://www.ruby-....

michael

8/9/2006 2:06:00 PM

0

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..


Patrick Spence wrote:
> michael wrote:
> > 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)
>
> }
>
>
> --
> Posted via http://www.ruby-....