You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Testcafe typeText函数无法在CKEditor中输入文本问题求助

解决TestCafe无法在CKEditor富文本编辑器中输入文本的问题

首先看你代码里最明显的问题:选择器拼写错误。你定位的元素class是ck-editor__editable,但代码里写成了ckeditor__editable(少了中间的横杠),这会导致TestCafe没选中正确的可编辑区域,自然输不进内容。

先修正选择器,试试这段代码:

const editable = Selector('.ck-editor__editable[contenteditable=true]');
await t
  .click(editable)
  .typeText(editable, 'test');

如果还是不行,试试定位编辑器内部的<p>标签——CKEditor的输入内容默认是放在这个标签里的:

const editorParagraph = Selector('.ck-editor__editable p');
await t
  .click(editorParagraph)
  .typeText(editorParagraph, 'test');

另外,也可以直接修改DOM内容(适合不需要模拟真实输入场景的情况):

const editable = Selector('.ck-editor__editable[contenteditable=true]');
await t.click(editable);
await editable.setContent('<p>test</p>');

如果编辑器初始化较慢,还可以加个等待确保元素完全就绪:

const editable = Selector('.ck-editor__editable[contenteditable=true]').with({ visibilityCheck: true });
await t
  .wait(500) // 等待编辑器加载完成,时间可根据实际调整
  .click(editable)
  .typeText(editable, 'test');

内容的提问来源于stack exchange,提问作者anon90

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 07:32:10