laechoppe laechoppe - 11 days ago 4x
Ruby Question

Capybara: How to attach a file?

I have an element, clicking which I open the dialog window of adding a picture:

<div layout="column" class="uploadPhotoActionBlock layout-align-center-center layout-column" layout-align="center center" ngf-select="vm.addPhotos($file)"
accept="image/*" ng-hide="vm.product.images.length == 3" aria-hidden="false"> <div flex="" class="plus flex"> + </div> <div flex="" class="text ng-binding flex"> add photo </div> </div>

I need to do these steps in my test.

I tried:

  1. attach_file

  2. find.set

  3. click button + click at (clicking inside the window)

Nothing works.
Browser is Chrome.
enter image description here

Any ideas? Thanks


You need to make the actual <input type="file"> element associated with the AddPhoto widget visible (you don't show the actual input in your html) and then call attach_file on that. Usually that will mean using execute_script to adjust the CSS of the input element to make it visible.