From what I can see, Angular is not actually using a placeholder
attribute to show the text you want.
Instead it uses a label
positioned over the select with css position: absolute
.
Angular select example page
This is the group of elements (simplified) - mat-select
and label
are siblings.
<div class="mat-form-field-infix">
<mat-select role="combobox" class="mat-select">
<div cdk-overlay-origin="" class="mat-select-trigger">
<div class="mat-select-value">
<span class="mat-select-placeholder"></span>
</div>
<div class="mat-select-arrow-wrapper">
<div class="mat-select-arrow"></div>
</div>
</div>
</mat-select>
<span class="mat-form-field-label-wrapper">
<label class="mat-form-field-label">
<mat-label>Favorite food</mat-label>
</label>
</span>
</div>
You want to test the text content of the mat-select
, but target it via the label text.
cy.viewport(1200, 1000)
cy.visit('https://material.angular.io/components/select/overview')
cy.contains('span', 'Favorite food')
.siblings('mat-select')
.invoke('text')
.should('be.empty')
// open the select
cy.contains('span', 'Favorite food')
.siblings('mat-select')
.click()
// choose option
cy.contains('mat-option', 'Tacos').click()
// check the select text has option value
cy.contains('span', 'Favorite food')
.siblings('mat-select')
.should('contain', 'Tacos')
Your select
cy.contains('span', 'Team Member')
.siblings('mat-select')
.click()
cy.contains('mat-option', 'Stage E2E').click()
cy.contains('span', 'Team Member')
.siblings('mat-select')
.should('contain', 'Stage E2E')