Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I'm trying to automate a scenario in which I have to upload document but I couldn't handle the File Upload window once I click the 'Choose File' button on my web application.

I'm using C# language and Chrome browser.

share|improve this question
    
What did you try ? Do you have any error message ? Please read how to ask and edit your question to improve your chance to receive answer :) – Cyril Durand Mar 31 at 22:45
    
Did you tried using SendKeys(path to file)? instead of clicking on Choose File try sending filepath using above said method. – Vivek Singh Apr 1 at 9:28

2 Answers 2

You can try the following if your File element has 'input type = file': element(by.css('input[type="file"]')).sendKeys(pathToFile);

This will not open up the File upload windows dialog. Rather this will send the required value to the input File field.

You can refer to the following links for details: http://seleniumeasy.com/selenium-tutorials/uploading-file-with-selenium-webdriver

How to Upload files using Selenium webdriver in Java

Regards,
Sakshi

share|improve this answer
    
Thank you, Sakshi for your response and here is the source for my control: <button class="btn btn-success" onClick="document.getElementById('upload').click(); return false;"> Choose File</button> <!--<![endif]--> <!--[if !IE]>--> <input type="file" name="docUpload.upload" value="" id="upload" onchange="showSpinner(); submit(action='AddFileToUpload')" style="max-width:0px; max-height:0px;"/> – ravi 0401 Apr 9 at 18:43
    
Is the suggested method working for you are there are some errors? – Sakshi Singla Apr 10 at 4:11
    
Unfortunately, Nope! As below vara prasad mentioned, I may have to use 3rd party tools/ kind of write own wrapper to handled these kind of windows popups unless you guys suggest any other workaround. – ravi 0401 Apr 13 at 18:38
    
What is the error/output when you use above mentioned approach? – Sakshi Singla Apr 14 at 5:28

Selenium doesn't have any inbuilt functions to handle file upload/interacting with windows dialogues(print dialogue)/windows popups.

If you want to interact with windows objects, you can use AutoIT

It is a great tool to interact with windows objects and very easy to use. See the below link for steps to work with.

http://www.toolsqa.com/seleniu-webdriver/autoit-selenium-webdriver/

share|improve this answer
    
Selenium provides the functionality to upload the File in most of the cases. stackoverflow.com/questions/16896685/…. seleniumeasy.com/selenium-tutorials/… – Sakshi Singla Apr 7 at 4:29
    
@SakshiSingla Selenium can handle only browser controls not OS controls. If your web application is handling file upload using browser controls, you can use selenium. If not handle those using some third party tools or coding language functions. seleniumeasy.com/selenium-tutorials/… – VaraPrasad Pakalapati Apr 7 at 8:42
    
Yes you are right but your answer gives a picture that Selenium cannot handle file upload. Please edit your answer to include the above information. – Sakshi Singla Apr 7 at 9:35
    
@SakshiSingla My answer is specific to asked question not generic. In the question above File Upload window is mentioned which is not browser window, it is OS specific window which can not be handled by Selenium. Read the question and my answer again to understand the problem Ravi is facing. – VaraPrasad Pakalapati Apr 7 at 9:55
    
If we click on File upload button on web application, then the behavior would be that Windows dialog will open. However, the same functionality can be handled in Selenium in a different way(without actually opening the windows dialog). In case it cannot be handled with Selenium, then AUtoIt is a good choice – Sakshi Singla Apr 7 at 9:58

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.