[英]How to I get a count of a selector and pass into a variable I can use later?
I am looking to get a row count of items returned so I can later add a filter to the list. 我希望得到返回的项目的行数,以便以后可以将过滤器添加到列表中。 Then I will assert that the filtered list number is less than the total number. 然后,我断言过滤后的列表号小于总数。
I have tried a number of .perform and .execute arrangements and continue to get undefined errors. 我尝试了多种.perform和.execute安排,并继续遇到未定义的错误。
module.exports = {
'Verify rows': function (browser) {
var value_id = 0;
browser
.url(browser.launchUrl)
.waitForElementVisible('body', 20000)
.pause(4000)
.verify.visible('div:nth-of-type(2) > form > div > div > div > div')
.assert.gdGreater('.offering-item-container', 0)
.execute(function () {
value_id = document.querySelectorAll('.offering-item-container').length;
})
.click('#IsGuaranteedToRun')
.pause(4000)
.assert.gdLess('#IsGuaranteedToRun', value_id)
}
};
I found an answer here that helped point me in the right direction. 我在这里找到了答案,这有助于我指出正确的方向。 Then I had to include the next steps within the callback. 然后,我必须在回调中包括后续步骤。
module.exports = {
'Verify rows': function (browser) {
var value_id = 0;
browser
.url(browser.launchUrl)
.waitForElementVisible('body', 20000)
.pause(4000);
const numElementsPromise = new Promise(resolve => {
browser.elements('css selector', '.offering-item-container', result => {
resolve(result.value.length);
});
});
numElementsPromise.then(result => {
value_id = result;
browser
.pause(4000)
.verify.visible('div:nth-of-type(2) > form > div > div > div > div')
.assert.gdGreater('.offering-item-container', 0)
.click('#IsGuaranteedToRun')
.pause(4000)
.assert.gdLess('.offering-item-container', value_id)
.click('#IsGuaranteedToRun')
.assert.gdEquals('.offering-item-container', value_id);
});
}
}; };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.