Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 上传文件selenium wd+;jQuery_Javascript_Jquery Ui_File Upload_Selenium - Fatal编程技术网

Javascript 上传文件selenium wd+;jQuery

Javascript 上传文件selenium wd+;jQuery,javascript,jquery-ui,file-upload,selenium,Javascript,Jquery Ui,File Upload,Selenium,存在包含以下元素的页面: <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> &

存在包含以下元素的页面:

<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>
问题似乎在于该站点使用jQuery上传脚本。以下是JS代码的相关部分:

  • (来宾用户无法看到脚本本身)
  • 两个链接,请分开:__http://www.dailypreptalk.com/components/com_dpt/assets/file-upload/js/jquery.fileupload.js">http://www.dailypreptalk.com/components/com_dpt/assets/file-upload/js/vendor/jquery.ui.widget.js_\uuu_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');");
    
    我就是不知道如何用预先填充的文件路径初始化jqueryupload小部件


    感谢您的帮助!

    使用机器人功能找到了解决方案:

    import java.awt.*;
    import java.awt.event.KeyEvent;
    
    原始代码+D:/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();
      }
    
    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();
      }