websterling has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use Win32::IEAutomation and have a problem. After going to the page, I'm trying to get all of the links on it using

my@links=$ie->getAllLinks();

This returns a list with elements in the form of Win32::IEAutomation::Element=HASH(0x19e698c)

Having read the doc for Win32::IEAutomation, I thought that

my$link=$ie->linkUrl($links[0]);

would return the link for the first element in the list (or any element depending on the index), but I get

Can't locate object method "linkUrl" via package "Win32::IEAutomation" at test line 20.

Obviously I've misunderstood something and would appreciate any guidance.
  • Comment on Win32::IEAutomation - Getting all links in a page

Replies are listed 'Best First'.
Re: Win32::IEAutomation - Getting all links in a page
by binf-jw (Monk) on Oct 18, 2008 at 17:48 UTC
    From looking at the documentation ( Can't test this as am currently away from my windows box ).
    Looks like you need to do something like this:
    my @links = $ie->getAllLinks(); $links[0]->linkUrl();
    linkUrl is a method of the 'link obj' not 'Win32::IEAutomation as stated: "Methods supported for link object". The object returned by 'getAllLinks' is 'Win32::IEAutomation::Element' which is the link obj. @links is therefore an array of objects 'hence the hash reference (How perl OO works see link below)'.
    You can peek inside what a ref variable is by using Data::Dumper
    Like so:
    use Data::Dumper; print Dumper( $link[0] );

    For more information have a look at at some of the perldoc tutorial on obj's perltoot understanding the insides really aids in the understanding of using them.
    Hope that helps
    - John
    Ps. use < code > tag in future when listing code in a post.
Re: Win32::IEAutomation - Getting all links in a page
by ikegami (Patriarch) on Oct 18, 2008 at 17:43 UTC
    The docs say linkUrl is a method for link objects, so I presume that should be
    my $url = $links[0]->linkUrl();
      You presume correctly!! Thanks for the reply.

        By the way, if you want the urls and don't have any other use for the link objects, you can use

        my @urls = map { $_->linkUrl() } $ie->getAllLinks();