当我执行
cy.get('#fsp-name').clear().type('random text');
如果文本已经有值可以说'assd asd adsdsd'并且我执行上面的命令我得到类似于'random textassd'的东西
我也尝试使用
cy.get('#fsp-name').clear().should('have.value', '').type('random text');
它在一段时间内起作用,在其他时候它提示它不等于 ' '。
我正在尝试在每个循环中执行此操作,如下所示
const data = [
{selector:'#name', newValue: 'John'},
{selector:'#phone', newValue: '1234567'}
];
cy.wrap(data).each(field => {
cy.get(field.selector).clear().should('have.value', '').type(field.newValue);
cy.contains('Save').click();
cy.visit('/abc/sdd');
cy.get(field.selector).invoke('val').should('equal', field.newValue);
});
最佳答案
尝试了上面提供的解决方案,但都没有帮助。
我最终使用了这个:
cy.get('#my-input-element').focus().clear();
如果这不起作用,那么不太愉快的解决方法是:cy.get('#my-input-element').invoke('val', '');
当 .type 以某种方式没有完成给定的字符串时(极少数情况):cy.get('#my-input-element').invoke('val', 'Some text here');
关于vue.js - cy.clear() 未正确清除输入字段 - Cypress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57378083/