REALLY waiting for element to load

Upvoted.

This is fine for a largely static web page, but for dynamic pages where javascript/ajax might be called upon to alter the dom, you may still run into timing/synchronization issues.

So please, be aware of the whole issue at hand.

FWIW, I do something very similar in custom Keyword Class/method that uses JavaScript right on the page to check if an element is ready. So your algorithm is fine but I’d advise you wrap it up into a Keyword method and use it everywhere.

Plus, prior to any of this, I have already waited for and proved everything I can think of to be ready:

URL is loaded (waitForPageLoad)
jQuery ready ($ is not undefined)
Ajax/jQuery not busy (check jQuery.active)
An HTML footer that appears on every page (check contents are visible)

So, by the time I come to check for a specific element, a lot of computing time has already been consumed waiting for that stuff without the need for forced, fixed-period, “best guess” delays.

While I’m here, I never could get sensible results from WebUI.waitForJQueryLoad.
It never seemed to take into account that upon loading, jQuery was very busy “doing things” and not in fact “ready” (which is why jQuery is loaded, right? It does stuff on the page… modifies the DOM, etc.). So I wrote my own which works reliably.

Anyway, I’m drifting the topic.

Good call Claudinho!

1 Like