'Cypress - Get [value] value property from mat-button-toggle-group
I have a selector to <mat-button-toggle-group [value]="myValue"></mat-button-toggle-group>
I want to have access to [value] value, and for that I do.
buttonToggleGroupSelector.should('exist').and('has.value', 'MyValue');
But this returns an empty string and not the attribute value.
Solution 1:[1]
When you use
buttonToggleGroupSelector.should('exist').and('has.value', 'MyValue');
Cypress is looking for a value property, but you want the value attribute
buttonToggleGroupSelector.should('exist').and('has.attr', 'value', 'MyValue');
Solution 2:[2]
You can use the invoke() method like so:
buttonToggleGroupSelector.invoke('attr', '[value]').should('eq', 'MyValue')
Solution 3:[3]
Assuming that buttonToggleGroupSelector returns something like cy.get('mat-button-toggle-group'), then you can do:
buttonToggleGroupSelector.should('have.attr', '[value]', 'myValue')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jumaane |
| Solution 2 | Manuel Abascal |
| Solution 3 | Alapan Das |
