<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 http://dropmocks.com/mEbKUV.

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.


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 https://stackoverflow.com/questions/3300580/webdriver-file-upload 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.

  • 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(By.id("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 stackoverflow.com/questions/3300580/webdriver-file-upload May 8 '14 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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