Download file for hidden input using protractor and selenium

I have a hidden file input field:

<input type="file" id="fileToUpload-1827" multiple="" onchange="angular.element(this).scope().setFiles(this)" data-upload-id="1827" class="hidden-uploader">

I would like to be able to upload files to this. The usual way to do this in a protractor would be to do:

ptor.findElement(protractor.By.css('.file-upload-form input')).sendKeys('/path/to/file')

But since the input element is not displayed, I get an error.

I tried:

  ptor.driver.executeScript("return $('.file-upload-form input')[0].removeClass('hidden-uploader');").then(function () {
    ptor.findElement(protractor.By.css('.file-upload-form input')).sendKeys('hello');
  })

But got an error

UnknownError: $(...)[0].removeClass is not a function

It seems ridiculous to use executeScriptto make an element visible so that I can upload a file, is there a better way? If not, how can I display the item?

Full html for input form:

<form class="file-upload-form ng-scope ng-pristine ng-valid" ng-if="ajaxUploadSupported">
<strong>Drag files here to upload</strong> or

<label for="fileToUpload-1953">
  <div class="btn btn-info select-file-btn">
    Click to Select
  </div>
</label>

<div>
      <input type="file" id="fileToUpload-1953" multiple="" onchange="angular.element(this).scope().setFiles(this)" data-upload-id="1953" class="hidden-uploader">
</div>
</form>
+3
source share
2 answers

The only way I could find this, after all, was to use javascript to make the input element visible.

, unhideFileInputs:

  var unhideFileInputs = function () {
    var makeInputVisible = function () {
      $('input[type="file"]').removeClass('hidden-uploader');
    };

    ptor.driver.executeScript(makeInputVisible);
  }

makeInputVisible, ptor.driver.executeScript(makeInputVisible). , jQuery, jQuery removeClass, .

, javascript webdriver, . ( executeAsyncScript, executeScript).

+6

user2355213s . ptor obsolote browser. , executeScript() .

browser.executeScript('$(\'input[type="file"]\').attr("style", "");');

. ,

browser.executeScript('$(\'input[type="file"]\').removeClass("hidden-uploader");');

HTML/CSS.

0

All Articles