I'm using Cucumber to test a comment form that doesn't have a submit button. I found that selenium has a method called send_key, which in theory should allow me to do this:
find_field('my-field').native.send_key(:enter)
But when I run my test, I get:
undefined method `send_key' for #<Nokogiri::XML::Element:0x007f874b361828> (NoMethodError)
Not a clue what I'm doing wrong. Any ideas?
You have to use the Selenium driver and not the :rack_test
driver in Capybara to access the send_keys
method:
selenium-webdriver
and add it to your gem file if you are using bundler.:js => true
so that it runs with the Selenium driver.You get an error because by default, Capybara uses the :rack_test
driver. Calling native
on an element access the driver specific methods. :rack_test
driver elements are implemented natively as Nokogiri::XML::Element
, therefore the send_keys
methods do not exists and you get this error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With