Dropzone.js: how to upload a file using selenium php-webdrivers

I use dropzone.js in my project, what I want to do is add the file manually to the queue without opening the file browser dialog, dropzone is already initialized with an element with the .imageDropzone class on the page, and I'm trying to run the following script to add a file.

Dropzone.autoDiscover=false;
var myZone=Dropzone.forElement('.imageDropzone');
var fileList=$("input[accept='image/jpg,image/gif,image/png,image/jpeg']")[0].files;
fileList.name="imageUploadTestJPG.jpg";
fileList.type="image/jpeg";
fileList.size=30170,
fileList.path="http://mysite/img/imageUploadTestJPG.jpg";
fileList.mozFullPath="http://mysite/img/imageUploadTestJPG.jpg";
fileList.accept="image/jpg,image/gif,image/png,image/jpeg";

console.log(fileList);
myZone.addFile(fileList);

why am i doing this?

1 . I am working with php-webdriver and I need to check download functionality,

2. The file browser dialog that opens after clicking on the file type input depends on the OS, it differs in different OSs and I cannot switch the control of this window, so I wanted to skip this process of opening a dialog with a file by clicking on it and you want to add manually file using javascript / jquery and saving autoProcessFiles=trueso that as soon as the file has been added, the download process starts, but I can not solve it.

when I try to call Dropzone.addFile(), I get the following

TypeError: argument 2 of form FormData.append does not implement the Blob interface

Event

I tried in a different way i.e.

1. , dropzone, dropzone change eventlistener file inputs, dropzone, change event listener , dropzone.

2. , <input type=file> dropzone.js script , php-webdriver , , .

0
1

,

FileList, myZone.addFile(). dropzone.js Dropzone.prototype.init ,

if (this.clickableElements.length) {

dropzone , document.body.appendChild(_this.hiddenFileInput);, dropzone change eventlistener , , , .

return _this.hiddenFileInput.addEventListener("change", function() {

, , FileList, .

files = _this.hiddenFileInput.files;

console.log(files), FileList FileList { 0=File, length=1, item=item(), more...} firebug

0          File { size=21789, type="image/png", name="1-7-2013 6-19-44 PM.png", more...}
length      1
__proto__   FileListPrototype { item=item(), @@iterator=@@iterator()}

, ,

_removeLink -----  a.dz-remove javascrip...defined; 
accept      -----  "image/jpg,image/gif,image/png,image/jpeg"   
accepted    -----  true 
mozFullPath -----  "http://mysite/img/imageUploadTestJPG.jpg"   
name        -----  "imageUploadTestJPG.jpg" 
path        -----  "http://mysite/img/imageUploadTestJPG.jpg"   
previewElement --   div.dz-preview  
previewTemplate --- div.dz-preview  
processing    ----- true    
size                30170   
status        ----- "uploading"
type                "image/jpeg"    
upload        -----  Object { progress=0, total=30170, bytesSent=0}
xhr            XMLHttpRequest { readyState=1, timeout=0, withCredentials=false, more...}
length             0
__proto__          FileListPrototype { item=item(), @@iterator=@@iterator()}

0 , , , FileList, , 0.

, , blob, xmlHttpRequest arraybuffer, blob URL , input.file Dropzone.addFile(). , dropzone.js

// Simulate a call to  service that can
// return an image as an ArrayBuffer.
var xhr = new XMLHttpRequest();

// Use JSFiddle logo as a sample image to avoid complicating
// this example with cross-domain issues.
xhr.open( "GET", "http://localhost/path/to/my/image.jpg", true );

// Ask for the result as an ArrayBuffer.
xhr.responseType = "arraybuffer";

xhr.onload = function( e ) {
    // Obtain a blob: URL for the image data.
    var arrayBufferView = new Uint8Array( this.response );
    var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
    var urlCreator = window.URL || window.webkitURL;
    var imageUrl = urlCreator.createObjectURL( blob );

    var parts = [blob, new ArrayBuffer()];

    file = new File(parts, "imageUploadTestFile", {
        lastModified: new Date(0), // optional - default = now
        type: "image/jpeg" 
    });

    $("input[accept=\'image/jpg,image/gif,image/png,image/jpeg\']").files = [file];
    myzone = Dropzone.forElement(".imageDropzone");
    myzone.addFile(file);
};
xhr.send();
+2

All Articles