Dom*_*ála 8 testing automation if-statement 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')}
Run Code Online (Sandbox Code Playgroud)
这是操场上的样子: 图片
还有那个复选框的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>
Run Code Online (Sandbox Code Playgroud)
Bre*_*dan 13
在 cypress 中没有内置的方法来做到这一点。我在我的测试中使用它:
if (Cypress.$("#yourElement").length > 0) {
// element exists, do something
} else {
// element does not exist, do something else
}
Run Code Online (Sandbox Code Playgroud)