赛普拉斯 - 如果那么起作用

Cypress - if then functions

我对赛普拉斯有疑问。

我在页面上有一个元素没有始终出现。什么时候显示什么时候不显示没有逻辑。

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

还有 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>

在赛普拉斯中没有内置的方法可以做到这一点。我在测试中使用它:

if (Cypress.$("#yourElement").length > 0) {
  // element exists, do something
} else {
  // element does not exist, do something else
}

您必须点击输入元素而不是标签:

cy.get('#p4-conditional-csob-interest-insurable-1').click();

无论如何,请查看赛普拉斯文档,因为强烈建议不要进行条件测试。