如何在柏树测试期间根据标签检查Mat-Checkbox?
Is it possible to check a mat-checkbox
in a Cypress test based on it's label text?
Below is the HTML for the checkbox:
I have several checkboxes to test, so I want to re-use code to do something like -
When I check the 'Advanced search' checkbox, When I check the 'Basic search' checkbox, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以使用简单
.contains()
的标签文本访问< mat-checkbox>
,但是您必须使用.click()
而不是.check()
。使用
.check()
给您错误The
<mat-checkbox>
can be accessed by label text with a simple.contains()
, but you must use.click()
instead of.check()
.Using
.check()
gives you the error如果
label
仅保留高级搜索
的复选框,则可以使用.contains()
label
作为选择器,以及复选框,然后.find()
要检查的复选框。这是一个工作
If the
label
only holds one check box forAdvanced search
, then you can use.contains()
withlabel
as the selector along with text of the checkbox, then.find()
the checkbox to check.Here is a working example.