From b30b60468d88160816812d97927028f31d68c3df Mon Sep 17 00:00:00 2001 From: Iain Beeston Date: Mon, 13 Mar 2023 17:16:25 +0000 Subject: [PATCH] Allow fill_in to work with reactjs React overrides the native setter of html input elements, so it doesn't fire change events when the value is changed. Because of that, for those input types where capybara uses javascript to change the value, change events are not fired as you'd expect when using react. I've updated the code to use the un-overridden value setter instead as recommended here: https://stackoverflow.com/a/46012210 I believe this shouldn't adversely affect apps using other javascript frameworks or no frameworks at all --- lib/capybara/selenium/node.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/capybara/selenium/node.rb b/lib/capybara/selenium/node.rb index cc8f37a73c..60ba4f6f9e 100644 --- a/lib/capybara/selenium/node.rb +++ b/lib/capybara/selenium/node.rb @@ -353,7 +353,9 @@ def update_value_js(value) arguments[0].focus(); } if (arguments[0].value != arguments[1]) { - arguments[0].value = arguments[1] + var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set; + nativeInputValueSetter.call(arguments[0], arguments[1]); + arguments[0].dispatchEvent(new InputEvent('input')); arguments[0].dispatchEvent(new Event('change', { bubbles: true })); }