[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Win32OLE Question

studlee2@gmail.com

7/8/2006 7:43:00 PM

All right, so I decided to write this *bubblegum* script while
practicing my Ruby scripting for windows automation. The test subject
is PhoneTrick.com

Background: When you enter the information, the site usually give you
a bogus reason as to why your call can't be completed. So why not
automate entering the information and have the script continually
submit it until the call is completed.

Can someone tell me how to get the focus to a button that doesn't have
a name? Below is the code so far and the last line is missing a value
between "_____" (feel free to look at PhoneTrick's source code):
/------------------------------------------------------------------/
require 'win32ole'

ie = WIN32OLE.new('InternetExplorer.Application')
ie.navigate("http://www.phonetrick...)
ie.visible = true
sleep 1 while ie.readyState() != 4
ie.document.all["PhoneNumberToDial"].value ="1231231234"
ie.document.all["CallerID"].value ="3213214321"
ie.document.all["CallerIDname"].value ="Matz"
ie.document.all["VoiceID"].value ="3"
ie.document.all["TextToSay"].value ="Ruby Rocks my Socks!"
#ie.document.all[""].click

/-------------------------------------------------------------------/

Thanks! _Steve

8 Answers

James Britt

7/8/2006 8:42:00 PM

0

studlee2@gmail.com wrote:
> All right, so I decided to write this *bubblegum* script while
> practicing my Ruby scripting for windows automation. The test subject
> is PhoneTrick.com

That appears to be a potential source of remarkable harassment.

And you want help in automating its use?



--
James Britt


studlee2@gmail.com

7/8/2006 8:50:00 PM

0

Ha! Good point, however the good folks at PhoneTrick have measures in
place to make sure people are abused or harrassed.

The main point is how do you get the focus on an object that doesn't
have a name - in this case the nameless button? Any ideas?

James Britt wrote:
> studlee2@gmail.com wrote:
> > All right, so I decided to write this *bubblegum* script while
> > practicing my Ruby scripting for windows automation. The test subject
> > is PhoneTrick.com
>
> That appears to be a potential source of remarkable harassment.
>
> And you want help in automating its use?
>
>
>
> --
> James Britt

Masaki Suketa

7/10/2006 12:05:00 PM

0

Hello,

In message "Re: Win32OLE Question"
on 06/07/09, "studlee2@gmail.com" <studlee2@gmail.com> writes:

> Ha! Good point, however the good folks at PhoneTrick have measures in
> place to make sure people are abused or harrassed.
>
> The main point is how do you get the focus on an object that doesn't
> have a name - in this case the nameless button? Any ideas?

Does the following example help you?
#
# The HTML file is following. The button does not have id.
# (But they have value.)
# <html>
# <body>
# <input type="button" value="button1" onclick="alert('button1')">
# <input type="button" value="button2" onclick="alert('button2')">
# </body>
# </html>
#
require 'win32ole'
ie = WIN32OLE.new('InternetExplorer.Application')
ie.visible = true
ie.navigate(URL_OF_HTML_FILE)
while ie.busy
sleep 1
end

# get button1
button1 = nil
ie.document.all.tags("input").each do |i|
if i.value == "button1"
button1 = i
break
end
end

# button1.click
if button1
button1.click()
end

Regards
Masaki Suketa


Patrick Spence

7/14/2006 2:01:00 PM

0

Solution using Watir module. Getting "frame error in waitdocument"
warnings which are being ignored in rescue blocks, but it works. Not too
sure what those warnings are all about!

require 'watir'

#-- startup IE
ie = Watir::IE::new()
ie.set_fast_speed

#-- login to site of "interest"
begin
ie.goto("http://www.phonetrick...)
rescue
#-- ignore "frame error in waitdocument" warning message
end

#-- populate form fields
ie.text_field(:name, "PhoneNumberToDial").set("6155551212")
ie.text_field(:name, "CallerID").set("6155551212")
ie.text_field(:name, "CallerIDname").set("Matz")

begin
ie.select_list(:name, "VoiceID").select("William - English")
rescue
#-- ignore "frame error in waitdocument" warning message
end

#-- populate remaining form field
ie.text_field(:name, "TextToSay").set("Ruby Rocks My Socks!")

begin
ie.button(:value, "Call!").click()
rescue
#-- ignore "frame error in waitdocument" warning message
end

#-- shut down IE
ie.close()
ie = nil



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

gekkonier

7/14/2006 3:02:00 PM

0

Maybe mechanize does the trick too?
http://mechanize.ruby...

Jeff

7/14/2006 7:20:00 PM

0

James Britt wrote:
>That appears to be a potential source of remarkable harassment.
>
>And you want help in automating its use?
>>studlee2@gmail.com wrote:
>> Ha! Good point, however the good folks at PhoneTrick have measures in
>> place to make sure people are abused or harrassed.
>>

Freudian slip? I'm sure they *do* make sure people are abused or
harrassed!

James's question was a good one, why are you trying to automate this
website?

Not trying to be a pain if you're really just trying to learn how to
automate IE - but if that's the case, why don't you pick a more
reasonable site (like your own) that we could help you with.

Jeff





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

studlee2@gmail.com

7/15/2006 3:17:00 AM

0

There are several reasons why I chose this site. First, it was more a
proof of concept than anything. The site just happened to be a website
I recently used where I filled out a form. I'm just trying to get more
experience automate windows tasks and I digressed to IE specifics.

I've been playing with Win32OLE a little bit and none of the examples
really explain how to get the DOM on a particular site. I figured out
that you could use the 'name,' but was stuck when there wasn't a name.
That's when I posted.

The suggestions you guys had were great.

On a side note, if you use Ruby as a calendar/reminder utility - this
part of the script could be integrated to call you with reminders or
appointments. Just a thought though. Not every site has to be used as
it was intended. And yeah, you caught my Freudian slip - I meant there
were measures in place so people are NOT harassed :-)

Thanks Everyone!

_Steve

William James

7/15/2006 3:41:00 AM

0


Masaki Suketa wrote:
> Hello,
>
> In message "Re: Win32OLE Question"
> on 06/07/09, "studlee2@gmail.com" <studlee2@gmail.com> writes:
>
> > Ha! Good point, however the good folks at PhoneTrick have measures in
> > place to make sure people are abused or harrassed.
> >
> > The main point is how do you get the focus on an object that doesn't
> > have a name - in this case the nameless button? Any ideas?
>
> Does the following example help you?
> #
> # The HTML file is following. The button does not have id.
> # (But they have value.)
> # <html>
> # <body>
> # <input type="button" value="button1" onclick="alert('button1')">
> # <input type="button" value="button2" onclick="alert('button2')">
> # </body>
> # </html>
> #
> require 'win32ole'
> ie = WIN32OLE.new('InternetExplorer.Application')
> ie.visible = true
> ie.navigate(URL_OF_HTML_FILE)
> while ie.busy
> sleep 1
> end
>
> # get button1
> button1 = nil
> ie.document.all.tags("input").each do |i|
> if i.value == "button1"
> button1 = i
> break
> end
> end

Very instructive. Thanks.

>
> # button1.click
> if button1
> button1.click()
> end
>
> Regards
> Masaki Suketa