我对赛普拉斯有疑问。
我的页面上有一个元素并不总是出现。什么时候显示、什么时候不显示,没有任何逻辑。
在 Cypress 中,是否有一些 IF/THEN 函数或其他函数,如何检查元素是否显示(因此填充它),当您没有看到它时,如何跳过该步骤?
我的代码:
if (Cypress.$('[data-bind="validationElement: interestInsurable"]').length > 0) {
cy.get('[for="p4-conditional-csob-interest-insurable-1"]').click()
}
else {cy.get('#car-info-serie')}
这就是它在操场上的样子:Picture https://i.stack.imgur.com/fDNFU.png
该复选框的 HTML 如下:
<label class="z-radio z-radio-inline primary" for="p4-conditional-csob-interest-insurable-1" data-bind="popover: { content: VehicleInsuranceTooltips.conditionalDataCsobInterestInsurable1Tooltip }" data-original-title="" title="">
<input id="p4-conditional-csob-interest-insurable-1" name="p4-conditional-csob-interest-insurable" type="radio" class="custom-radio" data-toggle="radio" data-bind="checkedValue: 1, checked: interestInsurable" value="1">
<span class="icons">
<span class="icon-unchecked"></span>
<span class="icon-checked"></span>
</span>
Patří vozidlo zájemci o pojištění?
</label>
在 cypress 中没有内置的方法可以做到这一点。我在测试中使用它:
if (Cypress.$("#yourElement").length > 0) {
// element exists, do something
} else {
// element does not exist, do something else
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)