2016-01-13 97 views
0

我在創建硒ide測試,現在我有問題。 我無法編寫從本地磁盤上傳文件的測試。用selenium ide上傳文件到Dropzone.js

我的懸浮窗的樣子: http://www.dropzonejs.com/examples/simple.html

有人能幫助我嗎?

+0

'''driver.get(「http://yourhost.com/uploadurl」); WebElement upload = driver.findElement(By.id(「id-of-file」)); upload.sendKeys(「/ your/file/to/upload.txt」); driver.findElement(By.id(「submit」))。click();''' – sfat

+0

這看起來不像是一個IDE問題。同時你應該看看像http://sqa.stackexchange.com/questions/12851/how-can-i-work-with-file-uploads-during-a-webdriver-test這樣的問題來解決這個問題。 – DMart

+0

感謝您的幫助。我正在尋找硒IDE的解決方案,但在這個時候我想把我的測試移動到Webdriver。 – mia654321

回答

0

我遇到同樣的問題,我找到了答案在這裏: How to interact with Dropzone using selenium

我最常用的,但我不得不創建我自己的方法來正確轉換爲base64。

public static String convertFileToBase64String(String fileName) throws IOException { 
 

 
     File file = new File(fileName); 
 
     int length = (int) file.length(); 
 
     BufferedInputStream reader = new BufferedInputStream(new FileInputStream(file)); 
 
     byte[] bytes = new byte[length]; 
 
     reader.read(bytes, 0, length); 
 
     reader.close(); 
 
     String encodedFile = Base64.getEncoder().encodeToString(bytes); 
 

 
     return encodedFile; 
 
    }

希望這有助於!