Imagine a webpage containing the following element:
<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>
The issue arises when a user clicks on the "Upload video" button above, as there is no "Attach" button, resulting in the native OS window opening for file selection.
Efforts to upload a file using Selenium WebDriver have proven unsuccessful with simple code snippets like:
driver.findElement(By.id("videoUpload")).sendKeys("D://Other//sample_videos//barsandtone.FLV");
driver.findElement(By.id("videoUpload")).click();
This problem appears to be linked to the site's utilization of a jQuery upload script. Here are the pertinent sections of JavaScript code:
- (restricted access for guest users)
- Separate links for: 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
Attempts to trigger JavaScript using:
js.executeScript("document.getElementById('videoUpload').value = 'D://Other//sample_videos//barsandtone.FLV'");
js.executeScript("document.getElementById('videoUpload').click()");
Yielded no positive outcomes. Similar efforts were made with jQuery initialization but to no avail:
js.executeScript("dpt.jQuery('#videoUpload').value = 'D://Other//sample_videos//barsandtone.FLV'");
js.executeScript("dpt.jQuery('#videosModal').modal('show');");
The challenge remains in understanding how to set up the jQuery upload widget with a pre-filled file path.
Your assistance is greatly appreciated!