Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Elusive button WWW::Mechanize::Firefox

by jjap (Monk)
on Aug 11, 2012 at 01:16 UTC ( #986845=perlquestion: print w/replies, xml ) Need Help??
jjap has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I am trying to get the hang of some automation with WWW::Mechanize::Firefox and can get as far as entering data in a form in what I think is a very simple case.

I tried various ways to activate/click/submit the "DECODE" button found on the page but to no avail. Here is my latest effort.
use strict; use WWW::Mechanize::Firefox; my $url = ""; my $agent = WWW::Mechanize::Firefox->new( activate => 1, autoclose => 0, ); my $sn = "1D7HU18D14J230995"; $agent->get($url); if ( $agent->success() ) { sleep(2); print "Retrieved $url\n"; $agent->form_name('Form'); $agent->field( 'dnn$ctr373$VINBox$tbVIN' => $sn ); sleep(2); $agent->submit_form( form => $agent->current_form()); }
Any hints would be appreciated.

Best regards!

Update: Corion's suggestion (click instead of submit_form) does the trick.

Also good references suggested by Anonymous to learn on CSS selectors for those, like me, not that familiar with these ways.

Thanks to all.

Replies are listed 'Best First'.
Re: Elusive button WWW::Mechanize::Firefox
by Corion (Pope) on Aug 11, 2012 at 06:48 UTC

    One approach could be to click the button instead of submitting the form:

    $agent->click({ selector => '#dnn_ctr373_VINBox_btnVIN' });
      Thanks Corion, that did it just fine.

      For my own info, where in the doc could I have found out about the hash key to add before the button id/name? Or is this some web convention not specific to the module?

      Thanks again for the boost!

        The syntax of CSS selectors is defined in some CSS standard, which WWW::Mechanize::Firefox uses. The documentation only mentions CSS selectors, but not their syntax or their definition. I guess that googling for them will turn up the relevant RFC or standard. Personally, I've mostly (re)used what others use and am not aware off-hand of a link to a standard.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://986845]
Approved by bulk88
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2018-04-19 10:22 GMT
Find Nodes?
    Voting Booth?