主要思想是:我有一份清单,beverage如果饮料是,并且有库存div,我想知道。它需要在JavaScript 中(没有 JQuery)checkout of stock or notclickfirst drink available
元素在这里hierarchy:
Main div包含所有饮料:class="ob-menu-items__items"
Each drink将在一个H4 class="ob-menu-item__title"
如果产品out of stock有span class="ob-menu-item__out-of-stock"text " - Out of Stock"
到目前为止,我尝试了这个(并卡住了):
for (var i = 0; i < 7; i++) {
// iterating over each drink.
var drink = document.getElementsByClassName("ob-menu-item__title")[i];
if (document.getElementsByClassName(".ob-menu-item__out-of-stock").parents(drink).length == 1) {
// There's out of stock text
// Do nothing and go to the next drink
} else {
//The product is available. Clik the drink and exit the loop
document.getElementsByClassName("ob-menu-item__title")[i].click();
break;
}
}
温温酱
富国沪深
RISEBY
UYOU
相关分类