小编典典

如何使用Webkit或Selenium驱动程序填充来自水豚的ckeditor

selenium

假设我使用的是具有JavaScript功能的驱动程序,例如capybara-
webkit或selenium,如何在Capybara中填充CKEditor区域?


阅读 326

收藏
2020-06-26

共1个答案

小编典典

从我在这里找到的内容启发,我想到了使用javascript在隐藏对象textareaCKEditor对象上设置数据的解决方案。视情况而定,两者似乎都不足够。

def fill_in_ckeditor(locator, opts)
  content = opts.fetch(:with).to_json # convert to a safe javascript string
  page.execute_script <<-SCRIPT
    CKEDITOR.instances['#{locator}'].setData(#{content});
    $('textarea##{locator}').text(#{content});
  SCRIPT
end

# Example:
fill_in_ckeditor 'email_body', :with => 'This is my message!'
2020-06-26