Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I am using Powershell to drive .NET Selenium and a FirefoxDriver to automate some stuff. Part of that is file uploads and the website happens to written (at least partly) with AngularJS.

Now I have figured out how to do automate the file upload with a normal input element. Just send the file path via SendKeys.

But I can't figure it out for this situation. The HTML for the file drop area with optional manual file selector is as follows:

<div class="overflowHidden video-drop-zone file-drop-zone zone appversionicon rounded"
ng-file-drop="onFileSelect($files);" ng-file-drop-available="dropSupported=true">               
    <div class="simpleDropZoneFileSelect">
        <span class="selectFileText">
            <span class="ng-binding ng-hide" ng-show="dropLabel !== undefined &amp;&amp; dropLabel !== ''"><br></span>
            <a class="ng-binding" href="" ng-show="true">Select file</a>
            <input class="" ng-show="true" ng-file-select="onFileSelect($files)" type="file">
        </span>
    </div>
</div>

I hope I haven't simplified this too much. And there surely is more to the whole AngularJS setup than that. But maybe it is enough for you to give me some pointers as to where to look next or how to approach this. If not, just let me know and I'll add more info.

I have found that Protractor seems to be the way to go when doing AngularJS testing, but it would alter my setup considerably (with a NodeJS server etc.) and all I need right now is this file upload.

Thanks!

Sandro

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Not sure how your entire set up looks like. But file upload is much easier in selenium.

Driver.FindElement(By.CssSelector("input[type='files']")).SendKeys("FilePath") 

should do it

share|improve this answer
    
Thank you for the input Saifur! As I said in my post, I am aware of that method. I can assume with some certainty that I have tried it on this one as well and that it didn't work. I'll try again to be sure tomorrow though –  Sandro Nov 3 '14 at 21:38
    
Tried that now. And it works!!!! :-) It didn't work at first, because the element wasn't visible (at absolute position -9999px) and the input couldn't be accepted because of that. That's why I must have abandoned that solution. Glad I have the "let's try again to be sure" mindset. Thank you Saifur! –  Sandro Nov 4 '14 at 6:48
    
I am glad that worked. I ran into similar issue because of not having the correct selector. –  Saifur Nov 4 '14 at 14:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.