SweetAlert2 click confirm while testing

I'm trying to click the sweetalert popup in my rails tests but it keeps telling me that it cannot find the button. My code looks like this:

it "should delete dummy user", js: true do
  user = FactoryGirl.create(:user)
  login user
  FactoryGirl.create(:course, :with_user_created)
  dummy_user = FactoryGirl.create(:dummy_user)
  visit booking_index_path("en")
  current_path.should eq(booking_index_path("en"))
  page.should have_content(dummy_user.name)
  page.find("#delete_dummy_" + dummy_user.id.to_s).trigger("click")
  click_button "Yes"
  page.should have_no_content(dummy_user.name)
end

And I'm getting the error:

Capybara::ElementNotFound:
   Unable to find button "Yes"

I'm calling sweetalert like so:

var modal_open = false;

$( document ).ready(function() {
  $(".alert-sweet").on('click', function(e){
    if (modal_open){
      modal_open = false;
      return true;
    }

    e.preventDefault();
    link = $(this);
    swal({
      title: "<%= t("you_sure") %>",
      confirmButtonText: "<%= t("t_yes") %>",
      cancelButtonText: "<%= t("t_no") %>",
      type: "warning",
      showCancelButton : true,
      confirmButtonColor : "#DD6B55",
      closeOnConfirm : false
    }).then(function() {
      modal_open = true;
      link.trigger('click');
    }, function(dismiss) {
      if (dismiss === 'cancel') {
        modal_open = false;
      }
    });
      return false;
  });
});

Any idea why Capybara cannot find the button? I've tried to print the hole page after click "#delete_dummy_" + dummy_user.id.to_s" and it seems that the button is there:

...
<div class="swal2-container">
  <div class="swal2-overlay" tabindex="-1"></div>
      <div class="swal2-modal" style="display: none; width: 500px; padding: 20px; margin-left: -250px; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial;" tabindex="-1">
        <div class="swal2-icon swal2-error" style="display: none;">
            <span class="x-mark">
                <span class="line left"></span>
                <span class="line right"></span>
            </span>
        </div>
        <div class="swal2-icon swal2-question" style="display: none;">?</div>
        <div class="swal2-icon swal2-warning pulse-warning" style="display: block;">!</div>
        <div class="swal2-icon swal2-info" style="display: none;">i</div>
        <div class="swal2-icon swal2-success" style="display: none;">
            <span class="line tip"></span> 
            <span class="line long"></span>
            <div class="placeholder"></div> 
            <div class="fix"></div>
        </div>
        <img class="swal2-image" style="display: none;">
        <h2>Are you sure?</h2>
        <div class="swal2-content" style="display: none;"></div>
        <input class="swal2-input">
        <select class="swal2-select"></select>
        <div class="swal2-radio"></div>
        <label for="swal2-checkbox" class="swal2-checkbox">
        <input type="checkbox" id="swal2-checkbox"></label>
        <textarea class="swal2-textarea"></textarea>
        <div class="swal2-validationerror"></div>
        <hr class="swal2-spacer" style="display: block;">
        <button class="swal2-confirm styled" style="background-color: rgb(221, 107, 85);">Yes</button>
        <button class="swal2-cancel styled" style="display: inline-block; background-color: rgb(170, 170, 170);">No</button>
        <span class="swal2-close" style="display: none;">×</span>
    </div>
</div>

EDIT:

Looks like the problem is because sweetalert is not visible. I already disabled the animations but still it's not turning it visible on clicking. Any suggestions?


ANSWERS:


Try to sleep:

page.find("#delete_dummy_" + dummy_user.id.to_s).trigger("click")
sleep(1)
click_button "Yes"


 MORE:


 ? SweetAlert2 add dynamic options to select input
 ? SweetAlert2 detect radio button select
 ? SweetAlert2 - if one button, it gets highlighted as soon as modal opens
 ? Can C/C++ build all dynamic libraries into one bin file?
 ? Can C/C++ build all dynamic libraries into one bin file?
 ? Can C/C++ build all dynamic libraries into one bin file?
 ? Relink a shared library to a different version of libc
 ? How does libc work?
 ? C/C++ Static vs dynamic libraries example
 ? GCC: Specifying static/dynamic libraries to build against