0

The following way of selecting a mat-option fails:

No element found using locator: by.cssContainingText("mat-option", "København K")

element(by.id('area')).element(by.cssContainingText('mat-option', 'København K')).click();

here is the HTML:

     <mat-select id="area" formControlName="area" placeholder="Working area">
  <mat-option *ngFor="let area of areas" [value]="area">
    {{ area }}
  </mat-option>

I don´t see why it fails.

CodeHip
  • 367
  • 5
  • 18

2 Answers2

2

Try : element(by.id('area')).click().then(()=>{ element(by.cssContainingText("mat-option","København K")).click(); });

To my understanding, mat-options are generated dynamically and will be in scope during the click() event. So you have to "click" and then work with the options.

Hope it works (and not too late :-) ).

0

Try this:-

element(by.id('area')).click();
element(by.cssContainingText('mat-option .mat-option-text', 'København K')).click();

As per my understanding above code must be working. Enjoy Protractor Coding :-)