4

I'm trying to automate uploading images in CasperJS.

The form on the site appears to be using plupload. Once a button is clicked, a file browser dialog appears where multiple images can be selected.

How can I handle this file upload form with CasperJS? Is it possible to upload multiple images all at once?

0

1 Answer 1

11

Even custom file upload widgets use an <input type="file" ...> element underneath their UI. That is necessary in order to get access to files on the client machine.

You can bypass the widget UI by directly setting the file that needs to be uploaded. Since CasperJS is built on top of PhantomJS, you can use all PhantomJS functions including page.uploadFile(selector, filename). In your case that would look something like this:

casper.page.uploadFile("#uploaders input[type='file']", myfilename);

Note that it is also possible to use all casper.fill*() functions provided you know the file input element name beforehand and the file input field is inside of a form element.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for answering @Artjom B., but i wonder, if the file images are separated in a different path,... how could we define that "myfilename" variable value anyway? separated by comma or something.... ? (seems strange).
@gumuruh It doesn't look like PhantomJS supports uploading multiple files to the same element, so CasperJS won't support it. I'm sure there is a workaround by copying the single file input as many times as you have files to upload and remove the "multiple" attribute from all of them. You can ask a question if you can't make it work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.