Using the Selenium Chrome driver in my JavaScript, I am constantly checking a value on a website every 2 seconds. However, I need to only save status changes to a text file, not every single check. The current code is functional but it saves the text file every two seconds. How can I modify it to store the status changes only? Please assist me with this.
setInterval(MyControl, 2000);
function MyControl() {
var x = browser.findElements(By.className("textclass")).then(function(divs) {
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());
fs.appendFile('mytextfile.txt', text + " Control Time: " + d.toLocaleString() + '\n', function(err) {
if (err) throw err;
});
});
});
} else {
console.log("There isn't any info :" + "Control Time :" + d.toLocaleString());
}
});
}