Reputation: 3413
I have a generated a button with javascript:
<script>
var button = document.createElement("button");
button.innerHTML = "Do Something";
var body = document.getElementsByTagName("body")[0];
body.appendChild(button);
</script>
but can't seem to be able to find that button using Capybara e.g:
find_button 'Do Something' or click_button 'Do Something'
produces Unable to find button "Do Something"
has anyone come across anything like this before?
Upvotes: 1
Views: 664
Reputation: 3413
Added to Gemfile and bundle install:
gem 'capybara-webkit'
Add to rails_helper:
Capybara.javascript_driver = :webkit
Enabled js on specific rspec scenario e.g:
scenario "dynamic button generated", js: true do
...
end
Upvotes: 1