Problem with jQuery 'change' event after using select to change selected option. #204

thegreatape opened this Issue Nov 25, 2012 · 9 comments


None yet
10 participants

When I use Poltergeist's select method to change the value of a select box, the event that is fired seems to have something wrong with its target property. With the html provided below in a route that's returned via a GET to '/', under Chrome 23.0, changing the value of the select fills in both the "from-target" and"globally" divs. However, under Capybara with the Poltergeist driver, only the "globally" target div is filled correctly- e.g. $(':selected').text() is incorrectly returning an empty string. A failing test for this is below.

    <title>jquery :select test</title>
    <script src="" type="text/javascript"></script>
        $('select').on('change', function(evt){
          $('.from-target').text( $(':selected').text() );
          $('.globally').text( $(':selected').text() )
    <label for="test-select">Test Select</label>
    <select name="test-select">
      <option value="1">A</option>
      <option value="2">B</option>
    <div class="from-target"> </div>
    <div class="globally"> </div>
require 'test_helper'

class JquerySelectTest < ActionDispatch::IntegrationTest
  test ":selected should work" do
    Capybara.current_driver = :poltergeist

    visit '/'
    select "B", from: "test-select"
    assert_equal "B", page.find('.from-target').text

I'm using PhantomJS 1.7.0 and Poltergeist 1.0.2 (with Rails 3.2.8), all under Mac OS 10.8.2. Please let me know if there's any more information that would be helpful in tracking this down.

marsch commented Dec 11, 2012

I experience the same problem, think that the change event is not bubbeling

teoulas commented Nov 12, 2013

This is a very old issue, but since I've experienced the same problem, I'll just mention my findings:
When running on a browser, the is the select element, but on phantomjs the is the option element. You can simply use event.currentTarget which is always the select element.

@teoulas - Thanks for adding your input - I also had an issue with giving the wrong value, using event.currentTarget instead fixes this.

Just curious why there's been no progress on this since it's been reported as of 2012. I just experienced the bug and wasted quite a bit of time. I had to work around this by manually executing javascript on the select to trigger a change event like:

page.evaluate_script("jQuery('#my_select').change()") if (Capybara.javascript_driver == :poltergeist)

Is there an active team fixing bugs for this project or must someone submit a pull request themselves with the fix?


yaauie commented Oct 20, 2014

@proteantech: There is no active, cohesive team; there are 4-5 volunteers with commit access, and we all have busy lives doing other things.

must someone submit a pull request themselves with the fix?

Yes. We're happy to review pull-requests & work with the community to isolate problems when we have the time, but AFAIK, none of our employers have given the directive to improve this project on company time, so forward movement of this project is entirely powered by the community.


jbaudanza commented May 19, 2015

Now that #581 is merged, I think this can be closed.


route commented May 19, 2015

Yep thanks!

route closed this May 19, 2015

Is there a plan to release a new gem version for this? Running off of head my specs pass, but the latest gem release breaks because select options aren't triggering the right events.

cseelus commented Jul 28, 2015

I read its issued for the next release, ran into problems too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment