admin管理员组

文章数量:1293987

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?

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?

Share Improve this question asked Sep 13, 2015 at 14:08 Willem-AartWillem-Aart 2,4604 gold badges20 silver badges29 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 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.

本文标签: javascriptJS file upload with PhantomJSCasperJSStack Overflow