# Activate radio button (win32ole)

**URL:** <https://www.ruby-forum.com/t/activate-radio-button-win32ole/174734>\
**Category:** Ruby\
**Created:** [September 1, 2009, 12:51pm UTC](https://www.ruby-forum.com/t/activate-radio-button-win32ole/174734 "2009-09-01T12:51:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![broken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4bbf92/32.png) [@broken](https://www.ruby-forum.com/u/broken)\
**Post date:** [September 1, 2009, 12:51pm UTC](https://www.ruby-forum.com/t/activate-radio-button-win32ole/174734/1 "2009-09-01T12:51:12Z")

</div>

Hi there folks!  
I am trying to automate a browser task with win32ole. The browser is  
Internet Explorer.

I used this tutorial:

> **[Automating Internet Explorer with Ruby: Without Watir](http://rubyonwindows.blogspot.com/2007/05/automating-internet-explorer-with-ruby_20.html)**
>
> In a previous post , I discussed how to use the watir library to automate Microsoft Internet Explorer. I should also mention that you can a...

So the code for clicking a normal button goes like

require ‘win32ole’  
ie = WIN32OLE.new(‘InternetExplorer.Application’)  
ie.Document.All.btnG.click

where ‘bntG’ is the name of the button.

The HTML for my radio button looks like this:

The problem is the name=“type”, I think.  
When I do this ‘ie.Document.All.type’ ooops, didn’t want to know it’s  
type…

Any way around this?  
I’d rather not use fat libraries like watir.

---

<div class="post-metadata">

**Author:** ![broken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4bbf92/32.png) [@broken](https://www.ruby-forum.com/u/broken)\
**Post date:** [September 1, 2009, 2:40pm UTC](https://www.ruby-forum.com/t/activate-radio-button-win32ole/174734/2 "2009-09-01T14:40:15Z")

</div>

Df Gh wrote:

> Hi there folks!  
> I am trying to automate a browser task with win32ole. The browser is  
> Internet Explorer.
> 
> I used this tutorial:  
> [Ruby on Windows: Automating Internet Explorer with Ruby: Without Watir](http://rubyonwindows.blogspot.com/2007/05/automating-internet-explorer-with-ruby_20.html)
> 
> So the code for clicking a normal button goes like
> 
> require ‘win32ole’  
> ie = WIN32OLE.new(‘InternetExplorer.Application’)  
> ie.Document.All.btnG.click
> 
> where ‘bntG’ is the name of the button.
> 
> The HTML for my radio button looks like this:
> 
> The problem is the name=“type”, I think.  
> When I do this ‘ie.Document.All.type’ ooops, didn’t want to know it’s  
> type…
> 
> Any way around this?  
> I’d rather not use fat libraries like watir.

A group of radio buttons will probably share the same control name, so  
you can’t reference an individual button by name.

But you can iterate over the input controls and check the one with the  
desired value:

ie.Document.All.Tags(‘input’).each do |control|  
if control.value == ‘reference’  
control.checked = true  
end  
end

Let me know if that works for you.

David

> **[Ruby on Windows](http://rubyonwindows.blogspot.com)**
>
> On using the Ruby programming language on the Microsoft Windows platform

---

<div class="post-metadata">

**Author:** ![broken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4bbf92/32.png) [@broken](https://www.ruby-forum.com/u/broken)\
**Post date:** [September 1, 2009, 2:57pm UTC](https://www.ruby-forum.com/t/activate-radio-button-win32ole/174734/3 "2009-09-01T14:57:47Z")

</div>

David M. wrote:

> A group of radio buttons will probably share the same control name, so  
> you can’t reference an individual button by name.
> 
> But you can iterate over the input controls and check the one with the  
> desired value:
> 
> ie.Document.All.Tags(‘input’).each do |control|  
> if control.value == ‘reference’  
> control.checked = true  
> end  
> end
> 
> Let me know if that works for you.
> 
> David
> 
> [http://rubyonwindows.blogspot.com](http://rubyonwindows.blogspot.com)

Thanks David, it works. I found out you can do it like this too:  
ie.Document.All.Type(3).Click  
Writing Type capitalized does the trick. And (3) stands for the 4th  
radio button element.

Now I have another minor problem.  
When the form is filled, I submit it via

> ie.Document.Forms(0).Submit

But before I can get the resulting links

> links = ie.Document.All.Tags(‘a’)  
> I have to do  
> sleep(1)  
> ie.Refresh  
> after the submit, or else I get the old page.

Any other way to get the updated results?

---

<div class="post-metadata">

**Author:** ![broken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4bbf92/32.png) [@broken](https://www.ruby-forum.com/u/broken)\
**Post date:** [September 1, 2009, 2:58pm UTC](https://www.ruby-forum.com/t/activate-radio-button-win32ole/174734/4 "2009-09-01T14:58:56Z")

</div>

Hi,

2009/9/1 Df Gh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ie = WIN32OLE.new(‘InternetExplorer.Application’)
> 
> Any way around this?  
> I’d rather not use fat libraries like watir.

You can use getElementsByName like this:  
ie.Document.getElementsByName(‘type’).item(0).click

Regards,

Park H.
