有元素的页面:
<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>
没有“附加”按钮,因此在单击上面显示的“上传视频”按钮时,用户会看到本机操作系统窗口,可以选择要上传的文件。
我无法使用 selenium WD 和简单的代码上传文件,例如不起作用:
driver.findElement(By.id("videoUpload")).sendKeys("D://Other//sample_videos//barsandtone.FLV");
driver.findElement(By.id("videoUpload")).click();
问题似乎是该站点使用 jQuery 上传脚本。以下是相关的 JS 代码部分:
- http://www.speedyshare.com/DEXEQ/main.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_ _ _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 上传小部件。
谢谢你的帮助!