Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clearing text in content-editable elements with set #2672

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/capybara/selenium/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/capybara/spec/session/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down