How to set text into Summernote textarea with Capybara + Poltergeist

半世苍凉 提交于 2019-12-01 18:41:04

Capybaras fill_in only works with html form elements. Since the JS version of your page is using a DIV with the contenteditable attribute as its text area to be filled #fill_in will not work. Instead you need to find the div and call #set on it directly. In your project the following should work

find('div[contenteditable]').set('This is awesome blog.')

After updating Summernote to 0.8.2, find('div[contenteditable]').set('This is awesome blog.') does not work.

I had to call Summernote API via execute_script like:

script = <<-JS
$('.some-field').summernote('editor.insertText', 'This is awesome blog.');
JS
execute_script(script)

EDIT

After updating Summernote to 0.8.2, find('div[contenteditable]').set('This is awesome blog.') does not work.

Sorry, this was not what I wanted to say. I should have said like this:

After updating Summernote to 0.8.2, find('div[contenteditable]').set('This is awesome blog.') does not fire Summernotes's onChange callback. So I had to call execute_script.

I have to test onChange behavior in my specs.

EDIT 2

As Thomas Walpole wrote, send_keys method could be used instead of execute_script. Thanks Thomas Walpole!

find('div[contenteditable]').send_keys('This is awesome blog.')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!