2013-09-30 38 views
0

有一个与元素页:上传文件硒WD + jQuery的

<div class="block-title-inside"> 
    <a href="javascript:void(0);" class="block-title-link fright" style="display:block; overflow: hidden; width: 105px;">Upload video <span class="blue-arrow-right"></span> 
    <input type="file" name="file" id="videoUpload" class="dpt-mediafile-input-button" style="z-index: 999"></a> 
Videos</div> 

没有“附加”按钮,同时点击“上传视频”上述用户显示按钮是看到本机操作系统窗口选择能力文件上传。

使用硒WD和简单的代码,我不能上传文件,如不能正常工作:

driver.findElement(By.id("videoUpload")).sendKeys("D://Other//sample_videos//barsandtone.FLV"); 
driver.findElement(By.id("videoUpload")).click(); 

的问题似乎是,该网站使用jQuery的上传脚本。以下是相关的JS代码的部分:

  1. http://www.speedyshare.com/DEXEQ/main.js(脚本本身不能被来宾用户可以看到)
  2. 两个环节,请分开:__http://www.dailypreptalk.com/组件/ com_dpt /资产/文件上传/ JS/jquery.fileupload.js“> http://www.dailypreptalk.com/components/com_dpt/assets/file-upload/js/vendor/jquery.ui.widget.js_ _ _http://www.dailypreptalk.com/components/com_dpt/assets/file-upload/js/jquery.fileupload.js

我试图运行JS代码:

js.executeScript("document.getElementById('videoUpload').value = 'D://Other//sample_videos//barsandtone.FLV'"); 
js.executeScript("document.getElementById('videoUpload').click()"); 

但仍然没有结果。我也尝试过使用jQuery代码初始化窗口,但没有机会,以及:

js.executeScript("dpt.jQuery('#videoUpload').value = 'D://Other//sample_videos//barsandtone.FLV'"); 
js.executeScript("dpt.jQuery('#videosModal').modal('show');"); 

我只是不能如何初始化的jQuery与预充式文件路径插件上传。

感谢您的帮助!

import java.awt.*; 
import java.awt.event.KeyEvent; 

原始代码+文件路径到d:

回答

0

将溶液用机器人功能发现/1.avi:

driver.findElement(By.id("videoUpload")).click(); 
    driver.getWindowHandle(); 
    //type path to your file using robot VK language 
    try { 
     Robot r = new Robot(); 
     r.keyPress(KeyEvent.VK_D); //D char 
     r.keyPress(KeyEvent.VK_SHIFT); // colon char 
     r.keyPress(KeyEvent.VK_SEMICOLON); // colon char 
     r.keyRelease(KeyEvent.VK_SEMICOLON); // colon char 
     r.keyRelease(KeyEvent.VK_SHIFT); // colon char 
     r.keyPress(KeyEvent.VK_BACK_SLASH); // backslash char etc 
     r.keyPress(KeyEvent.VK_1); 
     r.keyPress(KeyEvent.VK_PERIOD); 
     r.keyPress(KeyEvent.VK_A); 
     r.keyPress(KeyEvent.VK_V); 
     r.keyPress(KeyEvent.VK_I); 
     r.keyPress(KeyEvent.VK_ENTER); 
    } catch (AWTException e) { 
     e.printStackTrace(); 
    }