Activate radio button (win32ole)

D

Df Gh

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:
<input name="type" value="reference" title="get ref" type="radio">

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

David Mullet

Df said:
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:
<input name="type" value="reference" title="get ref" type="radio">

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
 
H

Heesob Park

Hi,

2009/9/1 Df Gh said:
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:
<input name="type" value="reference" title="get ref" type="radio">

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.

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

Regards,

Park Heesob
 
D

Df Gh

David said:
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?
 

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,736
Latest member
AdolphBig6

Latest Threads

Top