symfony / panther

A browser testing and web crawling library for PHP and Symfony
MIT License
2.9k stars 213 forks source link

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

Open MOSRob opened 2 years ago

MOSRob commented 2 years ago

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

russkibrazil commented 2 years ago

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...