在selenium上传JPEG,通过Selenium webdriver上传图片

时间:2015-09-17 08:21:32

标签: html selenium

HTML Snipit:

 <form id="frmUploadVisualAsset" enctype="multipart/form-data" method="Post"         action="uploadVisualAsset" novalidate="novalidate">
    <input id="slideIdForAsset" type="hidden" name="slideIdForAsset">
    <input id="courseIdForAsset" type="hidden" name="courseIdForAsset">
    <div class="form-group">
    <label class="col-md-3 control-label">
    <div id="visualUploader" class="col-md-6 upload-360">
    <**button id="**btnSelectFile**"** class="btn blue btn-browse" type="button"    style="position: relative; z-index: 1;">
    <button id="btnUploadCancel" class="btn btn-default btn-cancel hide" style="z-index:99999" type="button">
    <span style="display:block"></span>
    <span id="filePreview" class="file-preview hide">123.jpg (17 kb)</span>
    <span id="fileProgress" class="file-progress hide" style="font-weight:bold">    </span>
    <input id="filePath" class="uploaded-file valid" type="hidden" data-msg-required="File uploading has not been completed yet." required="" name="filePath" aria-required="true" value="" aria-invalid="false">
    <input id="imageWidth" type="hidden" name="imageWidth">
    <input id="imageHeight" type="hidden" name="imageHeight">
    <div id="html5_19vb34lfo1mbgnda11dh1gjq1li33_container" class="moxie-shim moxie-shim-html5 hide" style="position: absolute; top: 0px; left: 15px; width: 92px; height: 34px; overflow: hidden; z-index: 0;">
    </div>
    </div>``

1 个答案:

答案 0 :(得分:0)

使用以下代码:

driver.findElement(By.id("btnSelectFile")).sendKeys("Pass Absolute Path of JPEG file");

现在点击上传按钮。