Win32OLE Question

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

[email protected] 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?

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?

Hello,

In message “Re: Win32OLE Question”
on 06/07/09, “[email protected][email protected] 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.)

<input type=“button” value=“button1”

onclick=“alert(‘button1’)”>

<input type=“button” value=“button2”

onclick=“alert(‘button2’)”>

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

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

Maybe mechanize does the trick too?
http://mechanize.rubyforge.org/

James B. wrote:

That appears to be a potential source of remarkable harassment.

And you want help in automating its use?

[email protected] 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

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 :slight_smile:

Thanks Everyone!

_Steve

Masaki S. wrote:

ie.document.all.tags(“input”).each do |i|
if i.value == “button1”
button1 = i
break
end
end

Very instructive. Thanks.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs