hi i am using selenium chrome driver in my js. And i am checking value in website in every 2 seconds. here is my code. Value is checking every 2 seconds. and it has two value. like online or offline. i want write to text file for status changes. not for every check. here is my code. it is working but it save text file every two seconds. i want check every two seconds but i want save it in text only status changes. help me pls.
setInterval(MyControl, 2000);
function MyControl() {
var x = browser.findElements(By.className("textclass")).then(function(divs) {
// console.log("yy:",divs.length);
var d = new Date();
if (divs.length == 1) {
divs.forEach(function(element) {
element.getAttribute("title").then(function(text) {
console.log(text, " Control Time :", d.toLocaleString());
// playSound();
fs.appendFile('mytextfile.txt', text + " Control Time: " + d.toLocaleString() + '\n', function(err) {
// console.log("/////////////////////////////////////");
if (err) throw err;
});
});
});
} else {
console.log("There isnt any info :" + "Control Time :" + d.toLocaleString());
}
});
}