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

Hi All, I am new to perlmonks and glad I joined than any late ...:)

Currently using Win32::IEAutomation for preparing fetching data from webpage and creates a CSV file. The issue is I am not able to get the selected value of list using $tmp=$ie->getSelectList('name:', "selectList.index")->SelectIndex();

$tmp prints as Win32::IEAutomation::Elements=HASH(0x1..). Can someone please help in getting the actual value of the selected item in list?

The list has "Data", "Internet", "Perl", "Communication", "Broadband". In my case it is "Perl", and need to print "Perl" in my CSV instead of the HASH reference.

Thanks
Manoj

Replies are listed 'Best First'.
Re: printing value of HASH reference
by almut (Canon) on May 13, 2010 at 07:30 UTC

    Try using Data::Dumper to see what the hash contains:

    use Data::Dumper; ... print Dumper $tmp;

    Then, when you know its keys, you can say something like

    my $value = $tmp->{key};

    Update: err wait, I overlooked that it's a Win32::IEAutomation::Element object... That means, the proper way would be to check the docs or the source for what methods that type of object provides, and then call the respective method which would give you the desired value.

    Update2: actually, AFAICT, there is no ready made method for returning the selected item (only to set it), but the following might work (from a quick inspection of the source — I don't have Windows here to try):

    sub getSelectedItem { my $elem = shift; my $options = $elem->{element}->options; for (my $n = 0; $n < $options->length; $n++) { if ($options->item($n)->selected) { return $options->item($n)->innerText; } } return undef; } my $selected_value = getSelectedItem($tmp);

    (with multiple selections, this would return the first selected item, but you could of course easily modify it to return all selected items as an array or list)

Re: printing valur of HASH reference
by Anonymous Monk on May 13, 2010 at 19:28 UTC