Win32OLE Question

S

studlee2

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.com")
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
 
J

James Britt

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?
 
S

studlee2

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?
 
P

Patrick Spence

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.com")
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
 
J

Jeff Cohen

James said:
That appears to be a potential source of remarkable harassment.

And you want help in automating its use?

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
 
S

studlee2

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
 
W

William James

Masaki said:
Hello,

In message "Re: Win32OLE Question"


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.
 

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

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top