panther icon indicating copy to clipboard operation
panther copied to clipboard

Trying to upload a file to a form input field and upload file to website.

Open MOSRob opened this issue 2 years ago • 1 comments

Hi,

having some trouble uploading a file to a website. after creating a new instance and calling the form on the page i can not seem add the document to the form and then submit.

example of the code i am running.

$client = Client::createFirefoxClient();

$crawler = $client->request('GET', 'website_that_has_the_form');

$form = $crawler->selectButton('submit_button')->form();

$form['file'] = 'C:/location_of_file_i_want_to_upload'; $form['Password'] = 'anypass';

$crawler = $client->submit($form);

i get error of not finding the file input that's within the form tags.

when checking what the form brings back with

$form->getValues();

the file upload field is not in the list.

some other things i have tried are

$myInput = $crawler->filterXPath('.//input[@type="file"]'); $myInput->click(); // this returns saying it not clickable $myInput->sendKeys(C:/location_of_file_i_want_to_upload); // this returns doesn't accept multiple files

MOSRob avatar Jul 21 '21 14:07 MOSRob

If I am not mistaken, you should use $form->getFiles() to check what files were submitted. $form->getValues() returns values that are not binaries: strings, numbers...

russkibrazil avatar Sep 03 '21 01:09 russkibrazil