How to wait for div's display?

There is a function which simulates human actions
function Save() {
 var arrow = document.getElementsByClassName('sf-feed')[0];
arrow.click();
 var saveV = document.getElementsByClassName('sf-menu-item')[0];
saveV.click();
}

it should be performed after displaying the div which has element with the above class.
The problem is that after the call the variable in undefined, the div does not have time displayed.
How to wait for div to load the function executed?
setTimeout not working!
July 2nd 19 at 13:47
2 answers
July 2nd 19 at 13:49
Solution
Well, try like this:
function Save() {
 var arrow = document.getElementsByClassName('sf-feed')[0];
 if (arrow) {
arrow.click();
 var saveV = document.getElementsByClassName('sf-menu-item')[0];
saveV.click();
 } else {
 setTimeout(Save, 500);
}
}
July 2nd 19 at 13:51
suggested a terrible decision, in fact, a crutch. The DOM is a special object for these cases.

Find more questions by tags JavaScriptjQuery