One problem with Selenium is that when a page makes heavy use of AJAX request, Selenium doesn't know when the request finishes and therefore when it should start querying the page for the requested elements.
My idea to solve this issue was to put an invisible div
in the page that would contain a counter incremented each time an AJAX request finishes:
<!-- will be v1v after first AJAX requext, v2v after the second etc. -->
<div style="display: none;" id="ajaxcounter">v0v</div>
So in the Selenium testing code I can put lines like this:
WebDriverWait(self.driver, 10).until(
text_to_be_present_in_element((By.ID, "ajaxcounter"), "v1v")
)
# test stuff that depends on the first AJAX request
However, the above line raises selenium.common.exceptions.TimeoutException
, since apparently Selenium refuses to "see" the content of elements with style="display: none;"
(if I remove this display: none;
then Selenium works fine).
Is it possible to make Selenium see this one invisible element? It can complain about any other invisible elements normally, but still it should see just this one element.