Currently, I have a code that runs fine, but I am looking to modify it to run in a loop that counts the number of elements with the class="socal"
and tests each link.
module.exports = {
'Unitel Fitness - click' : function (browser) {
browser
.url('http://m.unitel.ao/fit/')
.execute('scrollIntoView(alignToBottom)')
.waitForElementVisible('.socal>span:nth-child(1) a', 6000)
.moveToElement('.socal>span:nth-child(1) a', 3, 3)
.pause(6000)
.click(".socal>span:nth-child(1) a")
.pause(6000)
.keys(['\uE006'])
.window_handles(function (result) {
var handle = result.value[1];
browser.switchWindow(handle);
browser.pause(1000);
//browser.assert.urlContains('facebook');
browser.closeWindow();
})
.end();
}
};
After upgrading the code, it is still not functioning as desired. The error message reads as follows: (I have attempted to provide more time for the process)
Number of links: 4 i val before execute: 1 i val before execute: 2 i val before execute: 3 i val before execute: 4 ? Timed out while waiting for element <.socal>span:nth-child("+ i +") a> to be present for 8000 milliseconds. - expected "visible" but got: not found
module.exports = {
'Social links' : function (browser) {
browser
.url('http://m.unitel.ao/fit/')
.execute(function(){
return document.querySelectorAll(".socal>span").length;
},
function(links) {
total_links = links.value;
console.log("Number of links: " + total_links);
for (var i = 1; i <= total_links; i++) {
console.log("i val before execute: " + i);
browser.execute('scrollIntoView(alignToBottom)');
//browser.waitForElementVisible('.socal>span:nth-child("+ i +") a', 8000);
//call back function
browser.waitForElementVisible('.socal>span:nth-child("+ i +") a', 5000, function() {
browser.moveToElement('.socal>span:nth-child("+ i +") a', 3, 3);
browser.pause(8000);
browser.click(".socal>span:nth-child("+ i +") a");
browser.pause(6000);
browser.keys(['\uE006']);
browser.window_handles(function (result) {
var handle = result.value[1];
browser.switchWindow(handle);
browser.pause(8000);
//browser.assert.urlContains('facebook');
browser.closeWindow();
})
});
}
})
// .end();
}
};