From: Guang C. <gua...@gm...> - 2017-08-10 00:13:55
|
On Thu, Aug 10, 2017 at 12:58 AM, José Román | Idiria S.L. < jr...@id...> wrote: > Hi, > > The web page I am working with has a javascript mechanism to attach some > files (images). The thing is that I cannot understand how to do it. There > are to methods; a) with direct drag & drop (which I understand is not > possible under HTMLUnit), b) through selection dialog. The thing is that I > don't know how to: > > 1.- Open the selection dialog (or simulate it). > 2.- Make JS process the selected files. > > The thing is that this is the first time I have to deal woth > HTMLUnit+Javascript and I am too new to understand how to invoke things > from Java to Javascript. > > It is clear the "upload-all" button does start the submission but I cannot > see how Javascript behaves when dropping an image. If I could perhaps I > could understand mechanics behind and imagine how to do things by myself... > Is there a way to make a "step-by-step" debugging with this JS code? > > Here you are the code of interest for this problem: > > <td class="main"> > > <script src="https://static.milanuncios.com/js/fotos/ > dropzone.4.2.0.min.js" type="text/javascript"></script> > <script src="https://static.milanuncios.com/js/fotos/exif.js" > type="text/javascript"></script> > <script src="https://static.milanuncios.com/js/fotos/ > dropzone-exif-extension.js" type="text/javascript"></script> > <link rel="stylesheet" href="https://static.milanuncios.com/css/fotos/ > dropzone.min.css"> > > <script type="text/javascript"> > function ver(id) { > document.getElementById(id).style.position = 'absolute'; > document.getElementById(id).style.display = 'inline'; > document.getElementById(id).style.visibility = "visible"; > document.getElementById(id).style.zIndex = '10000'; > } > > Dropzone.options.photoUploader = { > init: function() { > var myDropzone = this; > this.__photoId = 0; > this.__uploadingPhotos = false; > this.__isPhotoUploadDone = false; > this.__errorMessagePrevious = ""; > > this.on("thumbnail", function(file){ > ExifExtension.applyRotation(file); > }); > > this.on("success", function() { > if(this.__uploadingPhotos) > this.processQueue(); > }); > > this.options.url = function(files) { > if (files.length !== 1) { > alert("Error interno 5690, por favor intentalo más > tarde"); > return; > } > > var localPhotoId = ++myDropzone.__photoId; > > return "/images/upload-image-auth. > php?&idanuncio=239851259&clave=MldFNw%3D%3D&numfoto="+localPhotoId; > }; > > this.on("processing", function() { > ver('espera'); > document.getElementById('upload-all').disabled = true; > }); > > this.on("drop", function() { > this.__errorMessagePrevious = ""; > }); > > this.on("error", function(file, errorMessage) { > console.log("error: ", errorMessage); > if (file.status == "error") { > if (!file.accepted) { > this.removeFile(file); > } else { > errorMessage = this.options.dictResponseError; > } > if (errorMessage != this.__errorMessagePrevious) { > this.__errorMessagePrevious = errorMessage; > alert(errorMessage); > } > } > if(this.__uploadingPhotos) > this.processQueue(); > }); > > this.on("queuecomplete", function() { > this.__isPhotoUploadDone = true; > window.location = 'http://www.milanuncios.com/ > publicado/?idanuncio=239851259&contra=2WE7'; > }); > > var submitButton = document.getElementById("upload-all"); > submitButton.addEventListener("click", function() { > myDropzone.__uploadingPhotos = true; > if (myDropzone.getQueuedFiles().length == 0) { > myDropzone.emit("queuecomplete", ""); > } > else { > ver('espera'); > myDropzone.processQueue(); > } > }); > > var dropArea = document.getElementById("dropArea"); > dropArea.addEventListener("click", function() { > // Clean all the previous error messages > myDropzone.__errorMessagePrevious = ""; > }); > }, > paramName: "uploadFile1", > parallelUploads: 1, > maxFiles: 9, > uploadMultiple: false, > autoProcessQueue: false, // Prevents Dropzone from uploading > dropped files immediately > addRemoveLinks: true, > maxThumbnailFilesize: 5, > maxFilesize: 5, > thumbnailWidth: 100, > thumbnailHeight: 100, > imageWidth: 800, > imageHeight: 800, > acceptedFiles: "image/jpeg, image/gif ,image/png", > imageQuality: 0.8, > dictDefaultMessage: "<strong>Arrastra tus fotos aquí <br/> o > <br/> selecciónalas de tu equipo</strong><div class=\"btnAddPhoto\">Añadir > fotos</div>", > dictFallbackMessage: "Tu navegador no soporta arrastrar fotos > directamente.", > dictFallbackText: "Utiliza el método antiguo para subir > fotos.", > dictFileTooBig: "La fotos es demasiado grande.", > dictInvalidFileType: "Formato no permitido. Asegúrate que tus > fotos son JPG, JPEG, GIF o PNG.", > dictResponseError: "Error al subir tus fotos. Por favor, > inténtalo de nuevo más tarde.", > dictCancelUpload: "Cancelar", > dictCancelUploadConfirmation: "¿Estás seguro que deseas > cancelar la subida?", > dictRemoveFile: "Eliminar", > dictRemoveFileConfirmation: "¿Estás seguro que deseas eliminar > esta foto?", > dictMaxFilesExceeded: "No puedes subir más de 9 fotos." > }; > > window.onbeforeunload = function() { > if (Dropzone && Dropzone.instances[0] && > !Dropzone.instances[0].__isPhotoUploadDone) { > return "¿Realmente quieres irte sin subir tus fotos?"; > } > }; > </script> > > <div id="dropArea"> > <form action="/images/upload-image-auth.php" > method="post" class="dropzone dz-clickable" drop-zone="" id="photoUploader" > enctype="multipart/form-data"><div class="dz-default > dz-message"><span><strong>Arrastra tus fotos aquí <br> o <br> > selecciónalas de tu equipo</strong><div class="btnAddPhoto">Añadir > fotos</div></span></div></form> > </div> > > <div class="uploadBtnBox"> > <button id="upload-all" class="uploadBtn">Finalizar > publicación</button> > </div> > </div> > </div> > > > Working with JavaScript is case to case basis to make it work. When I work with Selenium before, I need to change to different drivers on which one will work for a specific site. Its really tricky. > > -- > > > *José Román Bilbao Castro* > > Ingeniero Consultor > +34 901009188 > > *jr...@id... <jr...@id...>**http://idiria.com > <http://www.idiria.com/>* <*http:// <http://%20%20/>idiria.com/ > <http://idiria.com/>*> > > -- > Idiria Sociedad Limitada - Aviso legal > > Este mensaje, su contenido y cualquier fichero transmitido con él está > dirigido únicamente a su destinatario y es confidencial. Por ello, se > informa a quien lo reciba por error ó tenga conocimiento del mismo sin ser > su destinatario, que la información contenida en él es reservada y su uso > no autorizado, por lo que en tal caso le rogamos nos lo comunique por la > misma vía o por teléfono (+ 34 690207492), así como que se abstenga de > reproducir el mensaje mediante cualquier medio o remitirlo o entregarlo a > otra persona, procediendo a su borrado de manera inmediata. > > Idiria Sociedad Limitada se reserva las acciones legales que le > correspondan contra todo tercero que acceda de forma ilegítima al > contenido de cualquier mensaje externo procedente del mismo. > > Para información y consultas visite nuestra web http://www.idiria.com > > > > Idiria Sociedad Limitada - Disclaimer > This message, its content and any file attached thereto is for the > intended recipient only and is confidential. If you have received this > e-mail in error or had access to it, you should note that the information > in it is private and any use thereof is unauthorised. In such an event > please notify us by e-mail or by telephone (+ 34 690207492). Any > reproduction of this e-mail by whatsoever means and any transmission or > dissemination thereof to other persons is prohibited. It should be deleted > immediately from your system. > > Idiria Sociedad Limitada reserves the right to take legal action against > any persons unlawfully gaining access to the content of any external > message it has emitted. > > For additional information, please visit our website http://www.idiria.com > > > > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Htmlunit-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlunit-user > > -- Guang <http://javadevnotes.com/java-string-split-space-or-whitespace-examples> |