使用 cypress 从 Mat-select 中选择选项 [英] Selecting options from Mat-select using cypress

查看:31
本文介绍了使用 cypress 从 Mat-select 中选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Mat-select 下拉菜单如下

I have Mat-select dropdown as follows

<mat-form-field>
   <mat-label>Gender</mat-label>
      <mat-select id="gender" required formControlName="gender">
         <mat-option id="Male" value="male"> Male </mat-option>
         <mat-option value="female"> Female </mat-option>
      </mat-select>
 </mat-form-field>

我正在尝试使用 Cypress 从字段中选择男性或女性.

I'm trying to use Cypress to select male or female from the field.

cy.get('mat-select').click().select('Male')

使用上面的代码,我得到以下错误:

With the above code I get the following error:

CypressError: cy.select() can only be called on a <select>. Your subject is a: <mat-select>

我需要一些帮助来解决这个问题,谢谢.

I need some help in fixing this, thank you.

对我有用的代码.

cy.get('#gender').click().then(() => {
            cy.get('#male').click()
        })

推荐答案

为 mat-select & 打开 mat-option 对话框选择包含Apple Inc."的字段.

Opens up the mat-option dialog for the mat-select & selects the field that contains "Apple Inc."

cy.get('mat-select[formControlName=companyName]').click().get('mat-option').contains('Apple Inc.').click();

这篇关于使用 cypress 从 Mat-select 中选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆