poltergeist
send_keys support for Poltergeist?
I want to switch from Selenium to Poltergeist but I need to simulate a barcode scanner that looks like keyboard entry to the <body> tag. I use this code with Selenium: native.send_keys(send_key) Is there a way with Poltergeist to send a string of keys to an arbitrary element (ie, not an input)?
Poltergeist now has send_keys support: element = find('input#id') # send a simple string element.native.send_key('String') # send a series of keystrokes element.native.send_keys('H', 'elo', :Left, 'l') # => 'Hello' # symbol for special keys element.native.send_key(:Enter) # triggers Enter key
Since PhantomJS 1.7 (released 2012-09-22), you can send keyboard events to the headless browser using page.sendEvent. The documentation includes an example simulating shift-A: page.sendEvent('keypress', page.event.key.A, null, null, 0x02000000 | 0x08000000 ); How exactly that input is handled by the page (i.e. what's targeted) will depend on the state of the page, such as where the focus is.
No, there is no way to do this at present. PhantomJS does provide an API for this, so it could be added in the future, but it's not currently supported. I'd suggest trying to generate the DOM keyboard events in Javascript. Or just keep those specs using Selenium and use Poltergeist for the rest.
Starting from version 1.5.0, poltergeist supports basic send_keys. https://github.com/jonleighton/poltergeist/blob/master/CHANGELOG.md#150
Related Links
How can I use “includeJs” function of phantomjs with poltergeist?
Poltergeist ruby gem fails to process `:shift` modifier in `send_keys`
Using Poltergiest to give user of app a screenshot of their page
Poltergeist 1.9.0 w/Ruby 1.9.3
Post via Capybara and Poltergiest for API testing
Poltergeist current_url command is returning page_info hash instead of a URL
How does one test the content of confirm dialogs using poltergeist?
Using Poltergeist, Phantom JS instances are not exiting during every rspec run
Render page element with padding in Poltergeist
Can I monkey patch the phantomjs browser api with execute_script?
send_keys support for Poltergeist?