我試圖通過鏈接列表循環,並對每個鏈接執行一些操作。我可以使用elements迭代元素,但在forEach中使用click並不會阻止forEach中的下一步,而Selenium會堅持下去,因爲它試圖繼續對不在DOM中的元素執行操作。WebdriverIO中的循環元素
var q = require("q");
var webdriverio = require('webdriverio');
var options = {
desiredCapabilities: {
browserName: 'chrome'
}
};
var clicks = [];
var runner = webdriverio.remote(options);
runner
.init()
.url('https://www.google.dk/search?q=burrito')
.elements(".r").then(function(res){
res.value.forEach(function(elem){
console.log(elem);
clicks.push(
runner
.elementIdClick(elem.ELEMENT)
.pause(5000)
.back()
.pause(2000)
);
});
return q.all(clicks);
});
如何確保forEach中的下一次迭代在所有代碼在forEach內部執行之前不會運行?
編輯:我應該提到我已經試過https://github.com/webdriverio/webdriverio/issues/941和https://github.com/webdriverio/webdriverio/issues/273。我用更具體的東西更新了我的代碼示例。
我應該提到,我已經嘗試過的解決方案,我可以在github。我更新了我的問題。抱歉。 – danielsvane