Capybara is not able to find an element on the page

I have an HTML form:

<%= form_with(url: '#', method: 'GET') do |f| %>
    <%= :client_id,
            .map{|c| [,]}, selected_client_id
        {include_blank: defined?(include_blank) ? include_blank : false},
            class: "form-control selectpicker border",
            id: "client_id",
            onchange: "this.form.submit()",
            data: {'live-search': true, style: "btn-white"}
<% end %>

I have a Capybara test:

    def check_grand_total(expected_value)
        visit current_path

        click_link "Balance"

        # this select has `onChange="this.form.submit()"` on it, so it should trigger a page load
        # however, the Capybara test fails and the screenshot appears as if it never selected
        # this option, even though the option is there, and I can manually click it myself
        select "Some Client", from: "client_id", visible: :all

        $stdin.gets # I threw in this line here to troubleshoot...
        # when the test pauses here, it does indeed appear as though Capybara didn't select anything

        # I tried adding this line here to manually trigger the change event
        # this doesn't appear to do anything either.

        actual_value = page.first('.grand-total').text
        assert_equal(expected_value, actual_value)

From all of the research I’ve done, it should “just work” and Capybara should “just wait” until the content appears on the page.

What’s weird is, sometimes this code works, sometimes it doesn’t. I’m pretty much baffled at why it works some of the time and not all of the time.

Got an answer here: ruby on rails - Capybara not finding content on page when it should? - Stack Overflow