Error trying to get attribute from element in Cypress

前端 未结 2 2009
野的像风
野的像风 2020-12-16 10:34

I have this HTML element:



        
2条回答
  •  盖世英雄少女心
    2020-12-16 11:22

    invoke() calls a jquery function on the element. To get the value of an input, use the function val():

    cy.get('input').invoke('val').should('contain', 'mytext')
    

    This is not the same as getting the value attribute which will not update with user input, it only presets the value when the element renders. To get an attribute, you can use the jquery function attr():

    cy.get('input').invoke('attr', 'placeholder').should('contain', 'username')
    

提交回复
热议问题