2

I'm writing a script that selects a size and adds the product to cart here is where it is http://store.nike.com/us/en_us/pd/free-4-flyknit-running-shoe/pid-1064825/pgid-1481072

use WWW::Mechanize::Firefox;
$mech = WWW::Mechanize::Firefox->new();

my $tconike = "http://store.nike.com/us/en_us/pd/free-4-flyknit-running-shoe/pid-1064825/pgid-1481072";

$mech->get($tconike);
print $mech->uri();
$mech->submit_form(
    form_number=> 2,
    fields => {
    skuAndSize => $shoesize,
    click => "ADD TO CART",
    }
);

But here is the output

Uncaught exception from user code:
        No form found to submit. at nikecartstandalone.pl line 25
 at C:/Users/Brett/Documents/brett/Perl/perl/site/lib/WWW/Mechanize/Firefox.pm l
ine 2162
        WWW::Mechanize::Firefox::signal_condition('WWW::Mechanize::Firefox=HASH(
0x2a54888)', 'No form found to submit.') called at C:/Users/Brett/Documents/bret
t/Perl/perl/site/lib/WWW/Mechanize/Firefox.pm line 3649
        WWW::Mechanize::Firefox::submit_form('WWW::Mechanize::Firefox=HASH(0x2a5
4888)', 'form_number', 2, 'fields', 'HASH(0x3501328)') called at nikecartstandal
one.pl line 25

Anyone know what I did wrong, is it because I should have used something besisdes submit_form or is it something else?

Chankey Pathak
  • 19,330
  • 10
  • 72
  • 119
Brett
  • 65
  • 5

1 Answers1

0

As the error says it's not able to find the form, so try submitting form with with_fields where you can specify the fields which are there in the form you are going to submit, that'll be easier to search and submit.

Eg: $mech->form_with_fields('username'); will select the form that contain a field named username.

Chankey Pathak
  • 19,330
  • 10
  • 72
  • 119
  • That did not work now I just got the error Uncaught exception from user code: `No elements found for form with fields [skuAndSize] at getsearchentities 1.pl line 77 at C:/Users/Brett/Documents/brett/Perl/perl/site/lib/WWW/Mechanize/Firefox.pm l ine 2162` That is just the beginning of it by the way, Is there some way to enter the shoe size (skuAndSize) and click the add to cart button outside of a form because it looks like perl just doesnt see that as a form? – Brett May 09 '14 at 12:12