Skip to content
Advertisement

upload a file in headless mode for robot framework

I’m writing an automated test in the robot framework and I need help to upload a file in headless mode for the below HTML code using robot framework libraries or some code in python or javascript or ajax.

<div class="mx-name-fileManager1 mx-fileinput mx-filemanager form-group no-columns" style="width: 95%; padding-left: 40px;">
    <label class="control-label" for="110.ServiceAsset.UploadDocument_SparePart.fileManager1.11_bch_133" id="110.ServiceAsset.UploadDocument_SparePart.fileManager1.11_bch_133-label">Upload Document
    </label>
    <div class="mx-compound-control" data-focusindex="0">
        <form class="sr-only" enctype="multipart/form-data" method="POST">
            <input type="file" tabindex="-1" accept=".pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.odt">
        </form>
        <input type="text" class="form-control" readonly="" aria-labelledby="110.ServiceAsset.UploadDocument_SparePart.fileManager1.11_bch_133-label" value="...">
        <button type="button" class="btn mx-button mx-fileinput-upload-button" id="110.ServiceAsset.UploadDocument_SparePart.fileManager1.11_bch_133-upload" aria-labelledby="110.ServiceAsset.UploadDocument_SparePart.fileManager1.11_bch_133-label 110.ServiceAsset.UploadDocument_SparePart.fileManager1.11_bch_133-upload">Browse...
        </button>
    </div>
</div>

Advertisement

Answer

You will have to use Robot Framework Selenium library, open browser and navigate to page where you need to upload. Then you can upload with this code snippet

Choose File    xpath://input[@type="file"]    ${CURDIR}/somefile.doc
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement