使用赛普拉斯单击特定的复选框

时间:2020-07-31 06:19:34

标签: angular unit-testing cypress

<div *ngFor="let item of items>
<div>
    <mat-checkbox
    id="checbox_1"
    [(ngModel)]="item.checked"
    (ngModelChange)="onCheckboxChecked()"
    ></mat-checkbox>
   </div>
</div>

使用上面的代码,它显示项目列表,每个项目都带有复选框。我试图单击一个特定的复选框并使用赛普拉斯进行测试。我需要一些帮助。谢谢。

尝试

cy.get('#mat-checkbox-1-input').click(); (unable to find element)
cy.get('#checbox_1').click() (is not visible because it has CSS property: `position: fixed` and it's being covered by another element:)

1 个答案:

答案 0 :(得分:0)

我终于通过这个实现了。

Container(
                  child: Column(
                    children: <Widget>[
                      Container(
                        alignment: Alignment.topLeft,
                        padding: EdgeInsets.only(left: 10.0),
                        child: Text("Random Text",
                            style: TextStyle(
                                fontWeight: FontWeight.bold,
                                color: Colors.black)),
                      ),
                      Container(
                        alignment: Alignment.topLeft,
                        padding: EdgeInsets.all(10.0),
                        child: Text("Owner",
                            style: TextStyle(
                                fontWeight: FontWeight.bold,
                                color: Colors.grey)),
                      ),
                    ],
                  ),
                ),