首页 > 解决方案 > 如何使用剧作家获得垫选元素的价值?

问题描述

我是 Playwright 的新手,我试图获取选定的选项值并将其更改为使用 playwright 的 mat-form-field 包含 mat-select 元素的另一个选项。

我试过了

await page.selectOption('select#colors', { label: 'Blue' });

即 selectOptions 不适用于垫选择元素

<mat-form-field>

<mat-select id="selectColor" [formControl]="colcorselect" (click)="$event.stopPropagation()"> <mat-option *ngFor="let filter of savedColorOptions" [value]="filter (click)="savedFilterChange($event, filter)"> {{filter}} </mat-option> </mat-select> </mat-form-field>

标签: angular-materialselectorplaywright

解决方案


这是最终对我有用的两个步骤:

  1. 首先单击它作为普通 UI 对象。

  2. 然后单击所需的选项值。

    let cmb_box_locator='mat-select[id="myCombo"]'
     await page.click(cmb_box_locator)
     await page.click('//span[@class="mat-option-text"][contains(.,"'+desiredValue+'")]')
    

推荐阅读