Activate radio button (win32ole)

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

I used this tutorial:

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.

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

http://rubyonwindows.blogspot.com

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

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?

Hi,

2009/9/1 Df Gh [email protected]:

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.

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