Manipulate IE via Ruby? Redux

Thanks very much for the MSDN link whoever sent it! I accidentally deleted your
original message, but I did get the link. :slight_smile:

I’ve been able to do this:

···

########
require ‘win32ole’

ie = WIN32OLE.new(‘InternetExplorer.Application’)
ie.visible = true

ie.gohome

ie.Navigate(“http://google.com”)
######################################

But now I would like to be able to get/set the value in the google search text
box. Can anyone show me how to do this?
I’ve been digging through the MSDN stuff, but I’m afraid I’m in a bit over my
head here. :frowning:

Would I need to somehow query IE to find out what text objects were on the
form? And then set them to the value I want? How would I then press the Search
button, or fire that event?

Christopher J. Meisenzahl CPS, CSTE
Managing Consultant - Software Testing
Spherion Technology
christopher.j.meisenzahl@citicorp.com

-----Original Message-----
From: Meisenzahl, Christopher J.
Sent: Monday, April 28, 2003 3:22 PM
To: 'ruby-talk@ruby-lang.org’
Subject: Manipulate IE via Ruby? …

I want to tinker with the concept of Windows Automation as described in chapter
16 of the PickAxe book.

Does anyone know where I can find the list of objects that can be manipulated
in IE via Ruby? Page 167 shows me how to launch IE, make it visible, and
navigate the “home” page. But I assume that so much more is possible. Can
anyone point me in the right direction?

If I could get to the point of navigating and filling in forms that would be
great!

Thanks very much in advance,

Christopher

Christopher J. Meisenzahl CPS, CSTE
Managing Consultant - Software Testing
Spherion Technology
christopher.j.meisenzahl@citicorp.com

def google_search(query)

require ‘win32ole’

ie = WIN32OLE.new(‘InternetExplorer.Application’)
ie.visible = true

ie.gohome

ie.Navigate(“Google”)

end

google_search(“ruby”)

-r.

···

christopher.j.meisenzahl@citicorp.com wrote:

Thanks very much for the MSDN link whoever sent it! I accidentally deleted your
original message, but I did get the link. :slight_smile:

I’ve been able to do this:

########
require ‘win32ole’

ie = WIN32OLE.new(‘InternetExplorer.Application’)
ie.visible = true

ie.gohome

ie.Navigate(“http://google.com”)
######################################

But now I would like to be able to get/set the value in the google search text
box. Can anyone show me how to do this?
I’ve been digging through the MSDN stuff, but I’m afraid I’m in a bit over my
head here. :frowning:

Would I need to somehow query IE to find out what text objects were on the
form? And then set them to the value I want? How would I then press the Search
button, or fire that event?

Christopher J. Meisenzahl CPS, CSTE
Managing Consultant - Software Testing
Spherion Technology
christopher.j.meisenzahl@citicorp.com

-----Original Message-----
From: Meisenzahl, Christopher J.
Sent: Monday, April 28, 2003 3:22 PM
To: ‘ruby-talk@ruby-lang.org’
Subject: Manipulate IE via Ruby? …

I want to tinker with the concept of Windows Automation as described in chapter
16 of the PickAxe book.

Does anyone know where I can find the list of objects that can be manipulated
in IE via Ruby? Page 167 shows me how to launch IE, make it visible, and
navigate the “home” page. But I assume that so much more is possible. Can
anyone point me in the right direction?

If I could get to the point of navigating and filling in forms that would be
great!

Thanks very much in advance,

Christopher

Christopher J. Meisenzahl CPS, CSTE
Managing Consultant - Software Testing
Spherion Technology
christopher.j.meisenzahl@citicorp.com

Rodrigo Bermejo | rodrigo.bermejo@ps.ge.com
IT-Specialist | 8*879-0644

########
require ‘win32ole’

ie = WIN32OLE.new(‘InternetExplorer.Application’)
ie.visible = true

ie.gohome

ie.Navigate(“http://google.com”)
######################################

But now I would like to be able to get/set the value in the google search
text
box. Can anyone show me how to do this?
I’ve been digging through the MSDN stuff, but I’m afraid I’m in a bit over
my
head here. :frowning:

My Internet Explorer Controller lib [http://www.clabs.org/ruby.htm]
encapsulates some of this.

Here’s how you’d do it directly:

require ‘win32ole’

ie = WIN32OLE.new(‘InternetExplorer.Application’)
ie.visible = true
ie.gohome
ie.navigate “http://google.com

while ie.busy
end

sometimes this isn’t necessary, but I’ve found in some cases ie.busy

returns too quickly. But checking for READYSTATE_COMPLETE by itself

isn’t

enough, because the browser won’t go out of READYSTATE_COMPLETE quickly

enough just after a new navigate call.

READYSTATE_COMPLETE = 4
until ie.readyState == READYSTATE_COMPLETE
end

form = ie.document.forms(0)
form.q.value = ‘cLabs’
form.submit

With my lib, some of this is simplified:

require ‘cl/iec’

def form
IEDomFormWrapper.new(@iec.form)
end

VISIBLE = true
@iec = ClIEController.new(VISIBLE)
@iec.navigatehttp://www.google.com
form.q = ‘cLabs’
form.submit

@iec.navigate automatically calls a wait method that handles the while
ie.busy and readystate nonsense.
form.q doesn’t require you to specify the .value on the end.

Chris
http://clabs.org

But now I would like to be able to get/set the value in the google search text
box. Can anyone show me how to do this?
I’ve been digging through the MSDN stuff, but I’m afraid I’m in a bit over my
head here. :frowning:

See Chris Morris’s IE controller code here http://clabs.org/ruby.htm

Stephen

± S.D.Sykes - www.stephensykes.com -

require ‘win32ole’

ie = WIN32OLE.new(‘InternetExplorer.Application’)
ie.visible = true
ie.gohome
ie.navigate “http://google.com

while ie.busy
end

It might be worth trying

while ie.busy
  sleep 0.1
end

since that should leave the CPU less busy, and hence more time available for
IE to complete its job!

READYSTATE_COMPLETE = 4
until ie.readyState == READYSTATE_COMPLETE
end

Ditto.

Regards,

Brian.

···

On Wed, Apr 30, 2003 at 01:31:32AM +0900, Chris Morris wrote:

It might be worth trying

while ie.busy
  sleep 0.1
end

since that should leave the CPU less busy, and hence more time available
for
IE to complete its job!

Duh – you’re right. Thanks for the heads up.

Chris