在使用Selenium几年之后,我开始学习Cypress。在Selenium中,我经常使用GetAttribute()方法。现在我正在尝试使用Cypress完成同样的操作,从以下HTML元素中打印class属性值:
<input class="form-control ng-touched ng-pristine ng-valid" max="21" min="1" type="number">
这是我的代码:
cy.log(cy.get('input').invoke('attr', 'class'));
输出:
log Object{5}
我尝试使用Lakitna的cypress-commands (https://github.com/Lakitna/cypress-commands),代码如下:
cy.log(cy.get('input').attribute('class'));
输出: