http://qs321.pair.com?node_id=1192948

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

Hi , I am trying to fill a form using the WWW::Mechanize module.
Logged in successfully now I have small form with 4 input fields for text.
and One Drag and drop Document upload option.
How can I upload the PDF file and submit the form ?
After the PDF gets uploaded only then I can see the submit button .
help me.
Image of the form
https://ibb.co/jOsJDQ
Thanks in advance.
when I dump the form bless( { # 'id' => 'chooseupload', # 'value' => undef, # 'name' => 'filename', # 'tabindex' => '-1', # 'value_name' => '', # 'type' => 'file', # 'size' => '40', # 'class' => 'filestyle', # 'style' => 'position: absolu +te; clip: rect(0px 0px 0px 0px);', # 'accept' => 'application/pdf +', # 'data-buttonname' => 'btn-de +fault' # }, 'HTML::Form::FileInput' ),
my perl code
my $mech = WWW::Mechanize->new(); $mech->cookie_jar(HTTP::Cookies->new()); $mech->get($url); $mech->field("id", $username); $mech->field("password", $password); $mech->click(); $mech->set_fields( identifier => [ 'xyzzzzz' ] , ConfirmationEmail => [ 'email@id.com' ] , tmpto => [ '13222222222222' ] , # pdfcreate=> [filename=> "UserAgent_Beschreibung. +pdf", # 'Content-Type' => 'application/pdf'], ); print $mech->content(); $mech->submit_form();

Replies are listed 'Best First'.
Re: Upload file and Form filling using the mechanise
by Corion (Patriarch) on Jun 16, 2017 at 21:43 UTC

    Have you determined whether the page requires Javascript?

    WWW::Mechanize does not support Javascript.

    The easiest approach is to sniff what the Javascript would send and then send the same data from Perl.

Re: Upload file and Form filling using the mechanise
by 1nickt (Canon) on Jun 16, 2017 at 16:06 UTC

    Hi, thanks for your post and code. Unfortunately I can't determine your real question or problem.

    In particular I cannot make out what you want to make happen with this line:

    $mech->('pdfcreate',["script.pdf", 'pdfcreate', ], # 1); ['Content-Type' => 'application/pdf'], );

    In order for you to get help it would help others if you could make two or three updates to your post:

    1. Describe your issue more clearly. "I want this to happen when I do this, but instead this happens."
    2. Post code that shows the issue as a SSCCE so it can be downloaded and run.
    3. Show the output you do get. In particular, read any error output and post the relevant parts of it below your code.

    See the documentation on how to best use this forum under the Information section at right.

    Thanks


    The way forward always starts with a minimal test.
Re: Upload file and Form filling using the mechanise
by smarthacker67 (Beadle) on Jun 16, 2017 at 21:39 UTC
    upated I hope this clears my question.