Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
<span class="span3 config_camera_wrapper img-rounded" style="border: 2px solid #fff;" align="center">
<img class="img-rounded" src="images/bookappt_v3/logo-placeholder.png" alt="140x140">
<i class="config_camera img-circle icon-camera icon-2x" onclick="$('#cropImageInput').trigger('click');"></i>.

Above is the code for upload image. Check the link to see the how the image upload option looks

I tried the below code to upload image.

WebElement upload = driver.findElement(By.xpath(".//*[@id='profile_configure_company_details']/div/div[2]/div/ul/li[3]/span[2]/i"));

But it doesnot works.

share|improve this question
possible duplicate of How can I work with file uploads during a Webdriver test? – Yamikuronue Apr 29 '15 at 16:37

As far as I know file uploads always need a <input type=file> tag in the HTML. Your example HTML does not contain any. Often its hidden somewhere in the page, so that input element is not shown on the page. It could also be generated as you the onclick event fires. The example page you linked on dropmocks has no upload functionality, it does nothing (or I can't figure out how it should work).

Once you figured out where the <input> is located you can use your sendKeys() code on that element instead and it should work. Also see for more methods to upload a file with Selenium

I would ask advice of your development team, they surely can assist you to find the correct <input> tag and help making this test work.

For reference you look at this example/test styled file uploader or this question about file uploads without inputs.

share|improve this answer
I figured out the code for image upload.<span id="cropImageSpan"> <input id="cropImageInput" class="hide" type="file" name="Image">. Below is the code I tried. driver.findElement("cropImageInput ")).sendKeys("/Users/sathiyarengarajan/Desktop/bouquet1.jpg");. Browse file popup opens and testcase fails – STE May 8 '14 at 12:07
Guess the sendKeys is triggering the OS file-dialog. You should try the JavaScript way to inject the filename, see the accepted answer on – Niels van Reijmersdal May 8 '14 at 17:36

Your Answer


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.