I've been reading different answers for hours but couldn't find a solution for testing using select2 and Capybara (Webkit driver).
I want to select an option from the select2 and, after that, check if some element value has changed (selecting and option fires an event to add a fee to a number that is in the view also). The problem is that I don't know how to select the element in order to fire the js event, because doing something like this works for the select but doesn't fire the js event:
select('VISA 4242 2020/10').select_option
(I've set the Capybara driver to use Webkit Javascript Driver)
This is the html before clicking on the select input (container is closed):
<fieldset class="form-group">
<label for="source_id">Payment Method</label>
<select name="source_id" id="js-payment-method" required="required" autofocus="autofocus" class="form-control normal-select2 select2-hidden-accessible" tabindex="-1" aria-hidden="true">
<option value="">Select a payment method</option>
<option value="ba_1">TEST BANK 6789 </option>
<option value="card_1">VISA 4242 2021/4</option>
<option value="ba_2">TEST BANK 1116 </option>
</select>
<span class="select2 select2-container select2-container--default select2-container--below" dir="ltr" style="width: 100px;">
<span class="selection">
<span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-js-payment-method-container">
<span class="select2-selection__rendered" id="select2-js-payment-method-container" title="VISA 4242 2021/4">
<span class="select2-selection__placeholder">Search...</span>
</span>
<span class="select2-selection__arrow" role="presentation">
<b role="presentation"></b>
</span>
</span>
</span>
<span class="dropdown-wrapper" aria-hidden="true"></span>
</span>
</fieldset>
This is the html after clicking on the select input (container is opened):
<fieldset class="form-group">
<label for="source_id">Payment Method</label>
<select name="source_id" id="js-payment-method" required="required" autofocus="autofocus" class="form-control normal-select2 select2-hidden-accessible" tabindex="-1" aria-hidden="true">
<option value="">Select a payment method</option>
<option value="ba_1">TEST BANK 6789 </option>
<option value="card_1">VISA 4242 2021/4</option>
<option value="ba_2">TEST BANK 1116 </option>
</select>
<span class="select2 select2-container select2-container--default select2-container--below select2-container--open" dir="ltr" style="width: 100px;">
<span class="selection">
<span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="true" tabindex="0" aria-labelledby="select2-js-payment-method-container" aria-owns="select2-js-payment-method-results" aria-activedescendant="select2-js-payment-method-result-1rcw-card_1">
<span class="select2-selection__rendered" id="select2-js-payment-method-container" title="TEST BANK 6789 ">
<span class="select2-selection__placeholder">Search...</span>
</span>
<span class="select2-selection__arrow" role="presentation">
<b role="presentation"></b>
</span>
</span>
</span>
<span class="dropdown-wrapper" aria-hidden="true"></span>
</span>
</fieldset>
Thanks a lot!