2
我有以下用javascript編寫的自定義命令for nightwatch.js。我如何將其轉換爲使用jquery?如何使用jquery寫一個nightwatch自定義命令
exports.command = function (classId, indexIfNotZero) {
this.browser.execute(function (classId, indexIfNotZero) {
if (classId.charAt(0) == '.') {
classId = classId.substring(1);
}
var items = document.getElementsByClassName(classId);
if (items.length) {
var item = indexIfNotZero ? items[indexIfNotZero] : items[0];
if (item) {
item.click();
return true;
}
}
return false;
//alert(rxp);
}, [classId, indexIfNotZero], function (result) {
console.info(result);
});
};
我有點想回答這個問題,但是如果index等於0,'!index'條件也會解析爲true。這裏沒有問題,但爲了清楚起見'if(index === undefined)'更好。 – koehr