# Win32OLE Question

**URL:** <https://www.ruby-forum.com/t/win32ole-question/97633>\
**Category:** Ruby\
**Created:** [July 8, 2006, 9:45pm UTC](https://www.ruby-forum.com/t/win32ole-question/97633 "2006-07-08T21:45:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 8, 2006, 9:45pm UTC](https://www.ruby-forum.com/t/win32ole-question/97633/1 "2006-07-08T21:45:48Z")

</div>

All right, so I decided to write this _bubblegum_ script while  
practicing my Ruby scripting for windows automation. The test subject  
is [PhoneTrick.com](http://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](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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 8, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/win32ole-question/97633/2 "2006-07-08T22:42:20Z")

</div>

removed\_email\_address@domain.invalid 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](http://PhoneTrick.com)

That appears to be a potential source of remarkable harassment.

And you want help in automating its use?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 8, 2006, 10:51pm UTC](https://www.ruby-forum.com/t/win32ole-question/97633/3 "2006-07-08T22:51:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 10, 2006, 2:06pm UTC](https://www.ruby-forum.com/t/win32ole-question/97633/4 "2006-07-10T14:06:17Z")

</div>

Hello,

In message “Re: Win32OLE Question”  
on 06/07/09, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 14, 2006, 4:00pm UTC](https://www.ruby-forum.com/t/win32ole-question/97633/5 "2006-07-14T16:00:18Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 14, 2006, 5:07pm UTC](https://www.ruby-forum.com/t/win32ole-question/97633/6 "2006-07-14T17:07:03Z")

</div>

Maybe mechanize does the trick too?  
[http://mechanize.rubyforge.org/](http://mechanize.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 14, 2006, 9:19pm UTC](https://www.ruby-forum.com/t/win32ole-question/97633/7 "2006-07-14T21:19:54Z")

</div>

James B. wrote:

> That appears to be a potential source of remarkable harassment.
> 
> And you want help in automating its use?
> 
> > removed\_email\_address@domain.invalid 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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 15, 2006, 5:22am UTC](https://www.ruby-forum.com/t/win32ole-question/97633/8 "2006-07-15T05:22:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 15, 2006, 5:47am UTC](https://www.ruby-forum.com/t/win32ole-question/97633/9 "2006-07-15T05:47:22Z")

</div>

Masaki S. wrote:

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

Very instructive. Thanks.
