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.
-
can you please put your selenium code also? in questionHelping Hands– Helping Hands2015年01月23日 10:09:40 +00:00Commented 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.Helping Hands– Helping Hands2015年01月23日 10:13:24 +00:00Commented Jan 23, 2015 at 10:13
1 Answer 1
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");