0
votes

I looked through tons of upload threads but was not able to find the answer. Can someone please help. I have a browse button that lets me pick files to upload from my pc to the website. Here is the html code where the browse button is at on the website:

<input id="contentFileInput" width="110" type="file" height="30" name="contentFileInput" style="display: none;">
<object id="contentFileInputUploader" width="110" height="30" type="application/x-shockwave-flash" data="../../Scripts/uploadify.swf" style="visibility: visible;">
<param name="quality" value="high">
<param name="wmode" value="opaque">
<param name="allowScriptAccess" value="sameDomain">
<param name="flashvars" value="uploadifyID=contentFileInput&pagepath=/Content/&script=/Content/AsyncUpload/&folder=&width=110&height=30&wmode=opaque&method=POST&queueSizeLimit=999&simUploadLimit=1&fileDesc=*.mpeg;*.mpg;*.avi;*.flv;*.mov;*.mp4;*.wmv&fileExt=*.mpeg;*.mpg;*.avi;*.flv;*.mov;*.mp4;*.wmv&auto=true&sizeLimit=1258291200&fileDataName=Filedata">
</object>

I tried: WebElement elem = driver.findElement(By.xpath("//*[@id='contentFileInputUploader']")); elem.sendKeys("C:///video/file.flv");

but it doesn't do anything. I got the xpath from firepath in ff when I hover the browse button. Can someone please suggest what I can do? I am really stuck. Thanks in advance.

1
Why do you send keys to the button? What is the flow to upload your file? First you click on button > standard Upload file dialog will appear, then you click Ok and file uploaded to your website. Am I correct? - Aleh Douhi
that solution was provided by another post. I'm just pointing it out that it doesn't work for this particular type of button. You are correct in your assumption, but when the dialog appears, but in this case, the click method doesn't even work on this object. And even if it did open a window, you would no longer have control at that time. Anyone have any ideas? - twsel
Probably you should play with element <input> above. Try it in selenium IDE: type | contentFileInput | C:\\video\\file.flv. If it will work, then probably you should use JavaScript to type your value: ((JavascriptExecutor) driver).executeScript("arguments[0].value = 'C:\\video\\file.flv';", elem); - Aleh Douhi
Hi Aleh,I tried IDE as well, but even it doesn't recognize click on that button(it won't record that action). I think because that object is flash. I tried <input> element xpath("//*[@type='file']")); but that gives a bunch of errors. I think that is why firebug doesn't recognize that as a valid element. I think all of this has to do with the <object> type, but don't understand it fully to confirm 100% Anything else to try? - twsel
Sorry, I didn't understand, have you try type | contentFileInput | C:\\video\\file.flv? And I recommend not to use xpath. In your case it would be better to use find by Id: driver.FindElement(By.Id("contentFileInput")); - Aleh Douhi

1 Answers

0
votes

You have to use sendKeys() on the file input, not on the button. In the example html, you should use:

findElement(By.id("contentFileInput"))

instead of

findElement(By.xpath("//*[@id='contentFileInputUploader']"))

If the problem persists, you should take a look here:

http://saucelabs.com/blog/index.php/2012/03/selenium-tips-uploading-files-in-remote-webdriver