0

I'm using Firefox::Mechanize to scrape a website. I'm stuck on a dropdown menu which has an onchange event associated with it.

I'm able to select the option I wanted from the pulldown menu, and I'm able to verify this because the pulldown now shows the option I selected. But it doesn't trigger the onchange event associated with it.

I'm thinking I might need a "click" event after selecting my option, but I'm not sure exactly how to incorporate that.

Here is the bit of HTML:

<select class="" id="select20279" name="20279" onchange="selectAction(this, this.options[this.selectedIndex].value, '20279');">
    <option value="">please choose</option>
    <option value="edit">Edit</option>
    <option value="view">View</option>
    <option value="delete_now">Delete</option>
</select>

Here is my script:

use WWW::Mechanize::Firefox;

my $mech = WWW::Mechanize::Firefox->new( tab => 'current', autoclose => 0 );

$mech->get('http://www.mywebsite.com/');
$mech->select("20279", "view");

Thanks in advance.

happytuna
  • 19
  • 3

1 Answers1

1

Get the DOM element and then send the change or click event to it:

my $select = $mech->selector('#select20279', only => 1);
$select->__change();
# or
$select->__click();

See also

http://search.cpan.org/~corion/MozRepl-RemoteObject-0.39/lib/MozRepl/RemoteObject.pm

Corion
  • 11
  • 1
  • Thanks very much Corion. This worked, but I needed to make a slight change to the "selector" line. I needed to change "only" to "single". – happytuna Oct 27 '15 at 18:26