Forum: Ruby Attach to running IE instance without watir?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E21f82d0a440629fc1805a6250422eb6?d=identicon&s=25 Geoff Cheshire (gtcaz)
on 2007-01-16 07:07
Hi all,

I've done the Google thing for several days and I'm hitting a blank.
I'm wondering if there's a way to attach to a running IE process (on
Windows) by using win32ole alone.  I can do it with watir, ie =
Watir::IE.attach(:url, url), but I may need to do this on platforms that
don't have watir installed.

Thanks in advance for any pointers,
Geoff
97550977337c9f0a0e1a9553e55bfaa0?d=identicon&s=25 Jan Svitok (Guest)
on 2007-01-16 20:46
(Received via mailing list)
On 1/16/07, Geoff Cheshire <gtc@cheshirelaw.com> wrote:
> Hi all,
>
> I've done the Google thing for several days and I'm hitting a blank.
> I'm wondering if there's a way to attach to a running IE process (on
> Windows) by using win32ole alone.  I can do it with watir, ie =
> Watir::IE.attach(:url, url), but I may need to do this on platforms that
> don't have watir installed.
>
> Thanks in advance for any pointers,
> Geoff

Hi,

it's certainly possible. In programming ruby you'llfind an example how
to attach to running excel. Then you'll need to find out Explorer's
API -  it shouldn't be that hard (see MSDN etc.)
9d1db4326350cea545c52f11a2bfc3b2?d=identicon&s=25 Nathan Smith (Guest)
on 2007-01-16 22:22
(Received via mailing list)
On 1/16/07, Geoff Cheshire <gtc@cheshirelaw.com> wrote:
> Geoff
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

From looking at the Watir source, it appears that attach calls
attach_init,
which calls a method called attach_browser_window. That method calls
_find.
You can look at the implementaion here:
http://svn.openqa.org/fisheye/browse/watir/trunk/w...

Since you don't want to depend on Watir, it looks like you may need to
reimplement some of its functionality.

Thanks,

Nate
68db3bafb0a990bf605c4cf62bf85db0?d=identicon&s=25 Bret Pettichord (Guest)
on 2007-01-17 06:46
(Received via mailing list)
Geoff Cheshire wrote:
> I've done the Google thing for several days and I'm hitting a blank.
> I'm wondering if there's a way to attach to a running IE process (on
> Windows) by using win32ole alone.  I can do it with watir, ie =
> Watir::IE.attach(:url, url), but I may need to do this on platforms that
> don't have watir installed.

The Watir code uses win32ole to implement Watir::IE.attach. Have you
looked at it? It's open source and the latest code is in the repository
on OpenQA.org.

Bret
Bfa670ef2303deb7dec5a8027367b30b?d=identicon&s=25 David Mullet (mully)
on 2007-01-17 16:27
(Received via mailing list)
Geoff Cheshire wrote:
>
> --
> Posted via http://www.ruby-forum.com/.

IE objects are included in the Windows collection of the Shell object,
so you could do something like the following (code not tested):

shell = WIN32OLE.new('Shell.Application')
shell.Windows.each do | window |
    if window.Document.Title == 'Your Title Here'
       ie = window
    end
end

Mully
E21f82d0a440629fc1805a6250422eb6?d=identicon&s=25 Geoff Cheshire (gtcaz)
on 2007-01-17 16:33
David Mullet wrote:

> IE objects are included in the Windows collection of the Shell object,
> so you could do something like the following (code not tested):

Excellent -- I'll give it a go!  Thanks everyone for your help.  I've
been wading trough the watir source (oh man, that was a bad pun), but
it's nice to have a small snippet like that to get me started.

Thanks again, and I'll post back if I get it working.  (I'm working on a
preview in browser command for the e Text Editor, which uses TextMate
bundles--but Windows doesn't have AppleScript so I'm rewriting those
commands in ruby.)

-Geoff
E21f82d0a440629fc1805a6250422eb6?d=identicon&s=25 Geoff Cheshire (gtcaz)
on 2007-01-17 19:27
David Mullet wrote:

> shell = WIN32OLE.new('Shell.Application')
> shell.Windows.each do | window |

Do you how I'd look for the URL instead of window.Document.Title?  I'm
guaranteed to have a file name (with full path), but may not know the
title.  Or could you point me to the docs where I could find all the
methods and properties?  (I found them from IE, but not for
Shell.Application.)

Thanks again!
Geoff
Bfa670ef2303deb7dec5a8027367b30b?d=identicon&s=25 David Mullet (mully)
on 2007-01-17 20:26
(Received via mailing list)
Geoff Cheshire wrote:
>
> Thanks again!
> Geoff
>
> --
> Posted via http://www.ruby-forum.com/.

Each item in the the shell's Windows collection is an actual
InternetExplorer object, so once you get to that object you will
utilize the standard IE object's properties and methods:

ie.LocationUrl
ie.LocationName

Here's some IE object docs:

http://msdn.microsoft.com/workshop/browser/webbrow...

Mully
E21f82d0a440629fc1805a6250422eb6?d=identicon&s=25 Geoff Cheshire (gtcaz)
on 2007-01-17 21:35
David Mullet wrote:
> Each item in the the shell's Windows collection is an actual
> InternetExplorer object, so once you get to that object you will
> utilize the standard IE object's properties and methods:
>
> ie.LocationUrl
> ie.LocationName
>
> Here's some IE object docs:
>
> http://msdn.microsoft.com/workshop/browser/webbrow...

That's it!  window.LocationUrl was the ticket.

Thanks for your help!

-Geoff
68db3bafb0a990bf605c4cf62bf85db0?d=identicon&s=25 Bret Pettichord (Guest)
on 2007-01-26 06:51
(Received via mailing list)
On Jan 17, 12:27 pm, Geoff Cheshire <g...@cheshirelaw.com> wrote:
> Or could you point me to the docs where I could find all the
> methods and properties?  (I found them from IE, but not for
> Shell.Application.)

shell = WIN32OLE.new('Shell.Application')
puts shell.ole_methods
This topic is locked and can not be replied to.