Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3394670
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:11:52+00:00 2026-05-18T04:11:52+00:00

We’re using Selenium with the Java API and some Javascript user extensions. We use

  • 0

We’re using Selenium with the Java API and some Javascript user extensions. We use a lot of AJAX calls in our app. A lot of our tests fail randomly because sometimes the AJAX calls finish slower than other times so the page isn’t fully loaded. We fix that by waiting for specific elements or Thread.sleep. I was trying to find a way to instead just wait for the network traffic to finish. So that we could do this:

selenium.click("some JS button");
selenium.waitForNetwork();
assertTrue(something);

That way we can get rid of the thread sleep and have tests pass faster when the server responds faster and not have so many tests fail due to timing issues.

I haven’t been able to find a way to do this searching Google. Does anyone have any ideas how we can accomplish this? (Preferably either through Javascript or the Java API but all suggestions are welcome).

Note: the other variations of “waitFor” are not what I’m looking for. We’re already using those in clicks and other things. I’m looking for something that waits for the NETWORK TRAFFIC. Thanks for all the feedback, I’ll be trying out a couple of the suggestions, but I’m still open to other ideas.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:11:53+00:00Added an answer on May 18, 2026 at 4:11 am

    Update: I use the same method (wrapRequest) in the same way with Selenium2 and it still works. The only difference is that I don’t use a user extension. I just execute javascript to query the code that is loaded by the JSP.

    Here’s what we ended up doing.
    (Note, there are easier ways of getting if an Ajax call is running if you are always using only a single framework like JQuery. We had to jimmy-rig this a bit more because we have a few pages that use JQuery and a bunch that use GWT)

    I created a Javascript file that every page loads only if you’re testing. (I did this by including a snippet in our JSP’s template: if the testing querystring param is passed in as true, set a cookie. If that cookie is set, include the javascript file)
    This javascript file essentially wraps the XMLHttpRequest object to keep count of all the send requests:

    function wrapRequest(xmlRequest) {
        var oldSend = xmlRequest.prototype.send;
        xmlRequest.prototype.send = function() {
            var oldOnReady = this.onreadystatechange;
            oldOnReady = function() {
                oldOnReady.apply(this, arguments);
                // if call is complete, decrement counter.
            }
            // increment counter
            if(oldSend.apply)
                oldSend.apply(this, arguments);
            else if (oldOnReady.handleEvent) { //Firefox sometimes will need this
                oldOnReady.handleEvent.apply(this, arguments);
            }
        }
    }
    

    There’s a little more to it than that if async == false, but that should be easy enough to figure out.

    Then I added a function to the selenium user-extensions.js that simply looks like this:

    Selenium.prototype.getIsNetworkReady = function() {
        if(this.browserbot.topWindow.isNetworkReady) { //sometimes this method is called before the page has loaded the isNetworkReady function
            return this.browserbot.topWindow.isNetworkReady();
        }
        return false;
    }
    

    Also, notice the check on topWindow: this is because you get issues when an iframe is selected.

    Also, you will have to call the wrapRequest method on the XMLHttpRequest object of every iFrame that gets loaded. I do that right now using: document.addEventListener("DOMNodeInserted", onElementAdded, true); and then in onElementAdded I just grab the iframe when it’s loaded and pass in the XMLHttpRequest object. but that doesn’t work in IE so I’m looking for an alternative. If anyone knows of a better way to do that so it works in both IE and FF I would love to hear it.

    Anyway, that’s the gist of the implementation. Hope this helps anyone in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am reading a book about Javascript and jQuery and using one of the
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.