我的代码无法验证是否单击了此复选框。无论其选中还是未选中,它都会在每次迭代中单击该框。 我尝试了各种方法,但是都没有工作,因为期望值不匹配而引发错误。随后会检查和取消检查
continent: {
continentName, //the id
planetName //id of the belonging planet
},
city: {
cityName, //the id
countryName, // id of the belonging country
continentName, //id of the belonging continent
planetName //id of the belonging planet
}
答案 0 :(得分:0)
您可以预先使用isSelected
命令轻松地对其进行验证。
https://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.isSelected
尝试:
const isChecked = await checkbox.isSelected();
if (!isChecked) {
// perform click actions here
} else {
console.log('Checkbox was already clicked : ' + bEnabled);
}
答案 1 :(得分:0)
您可以轻松检查复选框是否已选中
var isChecked_1 = $(this).is(":checked");
if (isChecked_1) {
// checked action
}
else {
// Unchecked action
}