Selenium WebDriver: How to Handle Ajax Application

A common problem we face during automation using selenium WebDriver is to handle the ajax calls. It is difficult to know when the call is complete and page has been updated. There are several ways to handle the ajax calls. This blog describes them one by one.
We can handle Ajax calls in two ways:

  Hard Wait - this is most commonly used method but not recommended while doing the automation. Only in some exceptional cases use or for short time use it
·    JAVA: Use java method Thread.Sleep( to suspend execution for specified time. Syntax –

Thread.sleep(1000) // time unit is millisecond

·   Implicit Wait – An implicit wait is to tell WebDriver to stop the DOM for a certain amount of time. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance. Syntax –

driver.manage().timeouts().Implicitly Wait(10, TimeUnit.SECONDS); 
// Time is in  seconds or we can also change Unit in second argument 
 Explicit Wait: An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code. Sample code is as follows -

WebDriver driver = new FirefoxDriver();
WebDriverWait myDElement = new WebDriverWait(driver, 10)



Popular posts from this blog

Testing Webservice with SoapUI Having Windows Authentication

Data Driven Testing Using Selenium -WebDriver in Python

How to Re-run Failed Scenarios in Cucumber