API Testing:



How To Handle AJAX Calls Using Selenium WebDriver

Handle Ajax Calls using Selenium:

Handling AJAX calls is one of the common issues when using Selenium WebDriver. We wouldn’t know when the AJAX call would get completed and the page has been updated. In this post, we see how to handle AJAX calls using Selenium.

AJAX stands for Asynchronous JavaScript and XML. AJAX allows the web page to retrieve small amounts of data from the server without reloading the entire page. AJAX sends HTTP requests from the client to server and then process the server’s response without reloading the entire page. To handle AJAX controls, wait commands may not work. It’s just because the actual page is not going to refresh.

When you click on a submit button, required information may appear on the web page without refreshing the browser. Sometimes it may load in a second and sometimes it may take longer. We have no control on loading time. The best approach to handle this kind of situations in selenium is to use dynamic waits (i.e. WebDriverWait in combination with ExpectedCondition)

Some of the methods which are available are as follows:

Check this post for detailed explanation on WebDeriverWait

In the above post, we have discussed on titleIs() condition. Let’s see some other conditions in detail.

  1. titleIs() – The expected condition waits for a page with a specific title.
  2. elementToBeClickable() – The expected condition waits for an element to be clickable i.e. it should be present/displayed/visible on the screen as well as enabled.
  3. alertIsPresent() – The expected condition waits for an alert box to appear.
  4. textToBePresentInElement() – The expected condition waits for an element having a certain string pattern.

If you are not a regular reader of then I highly recommend you to signup for the free email newsletter using the below link.

Sharing is caring.

Share on facebook
Share on twitter
Share on linkedin

Like This Post?

We have a lot more where that came from?

We only send really good stuff occasionally, promise.

Rajkumar SM

8 thoughts on “How To Handle AJAX Calls Using Selenium WebDriver”

    1. Hi Saili Inamdar,
      Its not possible to click on an element which is not visible on the screen. You have to wait for the element to be loaded. Check out this post

      1. Thanks Raj for your reply.

        Now in my case, the web URL, doesn’t have scroll bar so that element will not be visible unless you zoom in the page. I do not want to use zoom in zoom out functionality as it is not recommended in my project. Then in this scenario, what should i do? Please guide.

        1. Hi Saili Inamdar,
          Can you please let me know
          1. Why it’s not recommended to use zoom in and zoom out.
          2. How you achieve the same behavior manually.

          1. Hi Raj,

            Zoom in zoom out is not recommended as higher authorities don’t want to change zoom from 100%.
            Secondly, guys those who are doing manual testing they perform zoom in zoom out. So BA out here is not allowing to have scroll bar and so i am unable to proceed.

          2. Hi Saili Inamdar,
            Selenium is a tool which automates browser. Selenium wont interact with hidden elements. But try JavaScriptExecutor. As you said even your manual testers are doing the same process. If nothing works, try to convince your team to run the script using zoom in zoom out. Also let me know the outcome of yours. Thanks.

          3. Thanks Raj. I will try for JavascriptExecutor and let you know.

            I tried doing by zoom in zoom out for submenu element but it is not working in my case. Can you please guide me on this as well so that any one solution would work.

Leave a Comment

Your email address will not be published. Required fields are marked *

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on whatsapp

Recent Posts:

Scroll to Top
API Testing eBook