Default type attribute of <button> not being respected
Hi,
As explained here: when a page contains multiple <button> elements (with the same name but different values), and one of those buttons is clicked, a different button's value shows up in the request params. For me it always seems to be the last button on the page but I haven't tested exhaustively yet. The correct behaviour is exhibited by an actual web browser and by Capybara's Rack::Test driver, and there's no JavaScript involved on this particular page, so my current workaround is to switch driver mid-scenario so that Rack::Test can submit the form.
Is this a capybara-envjs bug?
Cheers, -Tom
I think this is an xpath ordering assumption that is not guaranteed.
What do you mean? Only the clicked <button type="submit"> (or <input type="submit">) element should be included in the form serialization. If all buttons are being included in the serialization, with an arbitrary one "winning", that's a bug. Is this capybara-envjs's responsibility or is the problem in Capybara or envjs?
I was thinking it was actually clicking the wrong button. That's what that pull request talks about: there was a capy spec in that case that was failing for capy-envjs because there were multiple matches for the xpath selector that capy was generating and the spec was assuming it was going to select the first button. That's not a valid assumption.
If your selector to capy matches multiple buttons, capy will pick one, I believe, but it does so in a manner that doesn't guarantee which one it will pick. That's implementation dependent.
I was thinking it was actually clicking the wrong button. That's what that pull request talks about: there was a capy spec in that case that was failing for capy-envjs because there were multiple matches for the xpath selector that capy was generating and the spec was assuming it was going to select the first button. That's not a valid assumption.
If your selector to capy matches multiple buttons, capy will pick one, I believe, but it does so in a manner that doesn't guarantee which one it will pick. That's implementation dependent.
The selector's not the problem. Capybara matches the right button.
I put together this minimal Rails app to demonstrate the problem. capybara-envjs copes fine with <input type="submit"> and <button type="submit"> (tomstuart/capybara-envjs-button-bug@9a67d66) but fails with <button> (tomstuart/capybara-envjs-button-bug@4d2e7df) even though type="submit" is the default.
Of course my new workaround is to just provide type="submit" when generating the <button> tag, but capybara-envjs should work without it.
Edited title to better reflect the real issue.
Thanks for narrowing it down. It's probably an envjs issue.