Web Automation using Python/Selenium to upload a file through Dojo FileUploader

Viewed 166

Generally, it's simple to make automation using Selenium to upload a file and there are many solutions for it.

But, what I am facing for trouble is to implement web automation to upload a file through Dojo FileUploader.

    <div class="ux uploader dnd fluid webDriver_uploader enforce-validity-marker-class mtc-uploader" data-dojo-attach-event="click:_onClickDomNode,drop:_onDropDomNode,dragover:_onDragOverDomNode,dragleave:_onDragLeaveDomNode,mouseenter:_onMouseEnterDomNode,mouseleave:_onMouseLeaveDomNode" id="Uploader_0" lang="en" widgetid="Uploader_0">
      <i class="upload icon" data-dojo-attach-point="iconNode"></i>
      <input type="file" name="">
      <button type="button" class="ux button" data-dojo-attach-point="browseButtonNode" data-dojo-attach-event="blur:_onBlurBrowseButtonNode,click:_onClickBrowseButtonNode,focus:_onFocusBrowseButtonNode">Choose File
      </button>
      <button type="button" class="ux basic icon button hidden" data-dojo-attach-point="removeButtonNode" data-dojo-attach-event="click:_onClickRemoveButtonNode" title="Remove File">
        <i class="trash icon">
          <span class="description">Remove
          </span>
        </i>
      </button>
      <div class="placeholder label" data-dojo-attach-point="labelNode" data-dojo-attach-event="click:_onClickLabelNode">or drag and drop here
      </div>
    </div>

Please check this screenshot

I've tried to control the file open dialog after clicking the Choose File button. But it seems like it's impossible to interact between the selenium and file open dialog.

I am working on Ubuntu 18.04

1 Answers

Selenium can interacts only with browser and when choose file button get clicked it will open file explorer ( which is in OS).

Workaround : instead of opening file explorer popup you can pass directly file path to selenium which it can upload automatically. for Example : driver.findElementById().send_keys('filepath')

also you can use PyWinAuto to interact with file explorer for windows.(https://pywinauto.readthedocs.io/en/latest/).

Related