testing - Testcafe:如何将文本输入到光谱颜色选择器的隐藏输入中
问题描述
我正在尝试使用 将颜色代码发送到Spectrum 颜色选择器输入t.typeText(colorPickerInput)
,但此输入被隐藏并且 Testcafe 抛出错误。基于文档选项{ visibilityCheck: false }
在以下情况下不起作用typeText()
<input id="ember949" class="spectrum-color-picker ember-view" style="display: none;">
有没有其他方法来处理这个?
解决方案
TestCafe 旨在模拟真实的用户行为,因此您不能使用“display: none”样式在输入元素中键入内容。但是,您可以使用ClientFunctions机制设置输入值,该机制允许您编写任何自定义 JS 代码。
请看下面的例子:
import { ClientFunction } from 'testcafe';
const setInputValue = ClientFunction(() => {
document.querySelector('input.spectrum-color-picker').value = '';
});
fixture `fixture`
.page `http://example.com`;
test('test', async t => {
await setInputValue();
});
推荐阅读
- wordpress - Woocomerce 仪表板给用户
- javascript - 如何将axios标头中的数据获取到Vue中的组件
- python - 列表模式检查
- c# - C#:在网站的输入标签中输入一个字符串
- r - dplyr group_by 的数据表版本
- python - 带有 Python Turtle 的递归树
- javascript - Django/Ajax:如何异步过滤表单字段的查询集?
- html - 底部的 Srcoll iframe 日志文本
- python - 为什么我没有得到 python flask sqlalchemy 自动完成功能?
- c# - 有没有办法询问一些 nginx 服务器每个 ip 的连接限制?