嘗試使用selenium webDriver將圖像上傳到dropzone。已經意識到它爲站點dropzonejsdotcom,但如果我嘗試使用腳本爲reactJS dropzone(http://reactdropzone.azurewebsites.net/example/)我收到一條消息:「未知錯誤:Dropzone未定義」。ReactJS dropzone通過webdriver上傳文件
JavascriptExecutor executor;
public ReactDrpzn() {
Configuration.browser = "chrome";
this.executor = (JavascriptExecutor) WebDriverRunner.getWebDriver();
}
private By dropzone = By.cssSelector(".filepicker.dropzone.dz-clickable");
@Test
public void drzon() throws IOException, InterruptedException {
open("http://reactdropzone.azurewebsites.net/example");
$(dropzone).hover();
String script = "var myZone, blob, base64Image; myZone = Dropzone.forElement('.filepicker.dropzone.dz-clickable');" +
"base64Image = 'iVBORw0KGgoAAAANSUhEUgAAAO0AAABQCAYAAAD1GfIkAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAAEGSURBVHhe7dPBCcAwAAMxp/vv3ObRJQ4kMJ7gzrb3Doh4/gciRAsxooUY0UKMaCFGtBAjWogRLcSIFmJECzGihRjRQoxoIUa0ECNaiBEtxIgWYkQLMaKFGNFCjGghRrQQI1qIES3EiBZiRAsxooUY0UKMaCFGtBAjWogRLcSIFmJECzGihRjRQoxoIUa0ECNaiBEtxIgWYkQLMaKFGNFCjGghRrQQI1qIES3EiBZiRAsxooUY0UKMaCFGtBAjWogRLcSIFmJECzGihRjRQoxoIUa0ECNaiBEtxIgWYkQLMaKFGNFCjGghRrQQI1qIES3EiBZiRAsxooUY0UKMaCFGtBAjWkjZPk/PAZ8fwt/rAAAAAElFTkSuQmCC';" +
"function base64toBlob(r,e,n){e=e||\"\",n=n||512;for(var t=atob(r),a=[],o=0;o<t.length;o+=n){for(var l=t.slice(o,o+n),h=new Array(l.length),b=0;b<l.length;b++)h[b]=l.charCodeAt(b);var v=new Uint8Array(h);a.push(v)}var c=new Blob(a,{type:e});return c}" +
"blob = base64toBlob(base64Image, 'image/png');" +
"blob.name = 'file.png';" +
"myZone.addFile(blob);";
executor.executeScript(script);
Thread.sleep(3000);//смотрим результат
}
U可以從這裏https://github.com/SaneQ/Drpzn
原因是這會不會在瀏覽器控制檯的工作也。 DropZone對象位於反應環境內部,並且該對象在主窗口中不可用。所以你需要以某種方式首先暴露或獲得這個對象 –