Search code examples
poltergeist

Poltergeist ruby gem fails to process `:shift` modifier in `send_keys`


It appears that only the :Shift modifier doesn't work in Poltergeist.

Environment

  • Poltergeist gem 1.9
  • Phantomjs 2.1.1
  • OSX El Cap
  • Rails 4.2.6

The test code that appears to offend is:

#page.find('#category-text').send_keys [:Shift, '.'] page.find('#category-text').send_keys [:Alt, 'a']

In my code, I allow both shift-. (that is, the > symbol), and Alt-a to perform the same function. Both keys work in the browser (Chrome 50+, OSX), but only the 2nd line above works in the test.

Elsewhere in my code and tests, :Ctrl works fine.

Is this something peculiar to how :Shift works on an MBP perhaps?


Solution

  • The issue here is not the :shift key specifically, it's the use of '.' in combination with any modifier (:shift, :alt. :ctrl, etc...). The issue occurs because PhantomJS doesn't provide entries in its keyCode map for punctuation keys (https://github.com/ariya/phantomjs/commit/cab2635e66d74b7e665c44400b8b20a8f225153a) so they end up generating a keyCode of 0.

    As a workaround you can call

    page.find('#category-text').send_keys [:shift, :period]
    

    which should provide the expected results.

    Update: A fix for this is now in Poltergeist master and will be in the 1.11.0 release when it happens