-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Page#wait_for_loaded not reliable? #51
Comments
Because the Page.loadEventFired event hasn't been reliable either. PRs with a fully reliable method (that doesn't also hang if something in the page can't be loaded) would be great. One of the other things to consider is what exactly does page "loaded" mean?? |
Ah, I see. I'm assuming that I've tried replacing For right now, my solution is using evaluate_async_script(<<-JS)
window.addEventListener('load', () => {
arguments[0]('jQuery' in window ? jQuery.fn.jquery : null);
});
JS However, this does not appear to be 100% reliable in all situations either. |
Similar situation here. Mostly consistent is the best I can get, here's my solution:
|
@andrewr224 using |
Background
I use Apparition to automatically detect the presence of certain JavaScript frameworks on different websites. Basically, I load the site (using
#visit
), and then I run a script (using#evaluate_script
) that tries to obtain the version number (for instance,jQuery.fn.jquery
would return the jQuery version on a page that has jQuery installed).Issue
I've noticed that this method is not always reliable. Specifically, I can sometimes re-run the same script (on a site where jQuery is present) up to three times and get different results each time (either a JavascriptError,
nil
, or the expected result).Discussion
I've looked around the source code and noticed that Apparition tries to detect page load by periodically attempting to run JavaScript (in
Page#wait_for_loaded
), and when it succeed, it assumes the page is loaded.Before using Apparition, I've used the ChromeRemote gem to interface with Chrome, but for many reasons, Capybara with Apparition seems preferable. However, using the other gem, I was able to detect page loads more reliably by listening for the
Page.loadEventFired
event.I'm curious as to why Apparition does not use this approach, especially since a comment in
Page#wait_for_loaded
seems to indicate that it is known that the current method is not reliable?The text was updated successfully, but these errors were encountered: