From 0ab06d87018cb7609dd16b97720f10316623338d Mon Sep 17 00:00:00 2001 From: Boris Petrov Date: Mon, 5 Jun 2023 15:52:27 +0300 Subject: [PATCH] Fix clearing text in content-editable elements with `set` --- lib/capybara/selenium/node.rb | 6 ++++-- lib/capybara/spec/session/node_spec.rb | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/capybara/selenium/node.rb b/lib/capybara/selenium/node.rb index bb7c199daa..a746cf31c7 100644 --- a/lib/capybara/selenium/node.rb +++ b/lib/capybara/selenium/node.rb @@ -403,11 +403,13 @@ def set_content_editable(value) # rubocop:disable Naming/AccessorMethodName return false; JS + value = value.to_s + # The action api has a speed problem but both chrome and firefox 58 raise errors # if we use the faster direct send_keys. For now just send_keys to the element # we've already focused. - # native.send_keys(value.to_s) - browser_action.send_keys(value.to_s).perform if editable + # native.send_keys(value) + browser_action.send_keys(value.empty? ? :delete : value).perform if editable end def action_with_modifiers(click_options) diff --git a/lib/capybara/spec/session/node_spec.rb b/lib/capybara/spec/session/node_spec.rb index cc79f953b5..d0c5fd62ae 100644 --- a/lib/capybara/spec/session/node_spec.rb +++ b/lib/capybara/spec/session/node_spec.rb @@ -148,6 +148,8 @@ @session.visit('/with_js') @session.find(:css, '#blank_content_editable').set('WYSIWYG') expect(@session.find(:css, '#blank_content_editable').text).to eq('WYSIWYG') + @session.find(:css, '#blank_content_editable').set('') + expect(@session.find(:css, '#blank_content_editable').text).to eq('') end it 'should allow me to change the contents of a child element' do