Selenium waits for async resource calls before proceeding to a new page.
Ex.
<script src="https://apis.google.com/js/platform.js" async defer></script>
On a website with many external apis (such as Google Analytics and share buttons from G+, Facebook, and Twitter). Selenium spends more time waiting for async calls than it does running tests.
Is there anyway to disable this behavior, so that selenium does not wait for async external api calls?
What you see is page load timeout in action. You can tweak it and handle the timeout exception:
try:
driver.set_page_load_timeout(5) # in seconds
except TimeoutException:
pass
# continue with testing
In addition to it, you can also add an Explicit Wait to wait for a certain desired "action" element to appear, so that you can proceed with your tests immediately once the element appears.
You can also optimize it by blocking requests to certain domains that are non-relevant for your tests and would not hurt the page rendering and would not affect your tests. For instance, if you want to block Google Analytics requests:
You can also disable images, CSS or flash (if this is applicable in your case):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With