1

Currently I am trying to automate a HTML file upload.

For what ever reason the website that I am trying to do this on does not make it as straight forward as I would like them to make it..

This is their code for the file upload div

<div class="form-row">
 <div id="fileupload" class="fileupload">
 <div class="c-position-relative margin-vertical10">
 <ul id="loaded-files" class="upload-image-thumbs clearfix loaded-placeholder">
 <li class="upload-placeholder upload-image">
 <div class="uploadedImg"></div>
 </li>
 <li class="upload-placeholder ">
 <div class="uploadedImg"></div>
 </li>
 <li class="upload-placeholder ">
 <div class="uploadedImg"></div>
 </li>
 <li class="upload-placeholder ">
 <div class="uploadedImg"></div>
 </li>
 <li class="upload-placeholder ">
 <div class="uploadedImg"></div>
 </li>
 <li class="upload-placeholder new-line">
 <div class="uploadedImg"></div>
 </li>
 <li class="upload-placeholder ">
 <div class="uploadedImg"></div>
 </li>
 <li class="upload-placeholder ">
 <div class="uploadedImg"></div>
 </li>
 <li class="upload-placeholder ">
 <div class="uploadedImg"></div>
 </li>
 <li class="upload-placeholder ">
 <div class="uploadedImg"></div>
 </li>
 </ul>
 <div id="upload_btn" class="c-green-button c-rounded-corners5 c-large">
 Add pictures
 <input type="file" name="file" multiple="">
 </div>

Now I would love to either send raw javascript to click() the object or even select the element with By.Id('') and open it this way but this does not seem to work.

I know the element can be opened when it is highlighted and an enter key is sent by yet again I cannot seem to get this to work.

Looking for some ideas and/or solutions.

All keys that are sent need to be directed to the Selenium WebDriver rather than being executed from windows itself as the user will be interacting with a WinForm.

Helping Hands
5,40410 gold badges68 silver badges134 bronze badges
asked Jan 23, 2015 at 10:01
2
  • can you please put your selenium code also? in question Commented Jan 23, 2015 at 10:09
  • Did you try this? : driver.findElement(By.id("fileupload")).sendKeys("C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg"); - You can replace your picture path. Commented Jan 23, 2015 at 10:13

1 Answer 1

4

You can use the .SendKeys() method to do this. e.g.

var uploadBtn = WebDriver.FindElement(By.Id("upload_btn"));
uploadBtn.SendKeys("C:\\FilePath\\File.txt");
Helping Hands
5,40410 gold badges68 silver badges134 bronze badges
answered Jan 23, 2015 at 11:15
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.