How To Solve Synchronization Failures In Selenium or QTP?

Share and Enjoy !

While automation testing using selenium tool for webpages , I am facing issue with Synchronization. Individually tests are passing. But while running in nightly mood manner, these are failing. One step failure leads to multiple failures in my testing.
I tried with Thread.sleep(30)..but found that is very much unreliable and prone to error. 
Thread.sleep will halt script at the step we are using and not at every step. selenium.setspeed halts script after each action/step performed on the application and this will be time consuming way.
I was googling for solution ..and I found this link . This is a very nice solution indeed. Even the latches given here. . is good to me. 

This is one important aspect of QTP automation test execution.Application speed depends on several external factors but QTP executes the code faster. In such condition it may so happen that QTP execution becomes faster than application . In this case execution fails.To avoid such condition we can use the below for synchronization:

  • Checkpoints applicable for UFT/QTP
  • Adding more sync time[wait]
  • Inserting synchronizing point
  • Through code like exists() or waitproperty()
In the same context, we can also see how to handle ajax calls:

  • Partial loading of website: It can be addressed by 
  • try{
    thread.sleep(<required time>);
    catch(Exception e)

  • Explicit wait:This will wait for a certain condition to occur before proceeding further
  • WebDriver driver=new FirefoxDriver();
    WebElement myDynamicElement=(new WebDriver Wait(driver,10)).until

  • Implicit Wait: It is to tell webdriver to poll the DOM for a certain amount of time when trying to find an element if they are not immediately available. The default settings is zero.Once set the implicit wait, it is set for the life span of the webdriver object instance. It is taken from watir.
  • WebDriver driver=new FirefoxDriver();
    WebElement element=driver.Element("myElement"));
  • Using Javascript
  • If an application triggers an ajax call, we need to wait until the call has ended. But using thread.sleep(),implicit or explicit wait is not clean and proper approach the browser does not change much while fetching data from server. jQuery keeps a count of how many ajax calls are active in its variable. The implementation is described here

    public void waitForAjax(int timeOutSeconds)
    if (driver instanceof JavaScriptExecutor)
    JavaScriptExecutor jsDriver=(JavaScriptExecutor) driver;
    for(int i=0;i<timeOutSeconds;i++)
    object numberOfAjaxConnections=jsDriver.executeScript("return");
    if(numberOfAjaxConnections instanceOf long)
    Long n=(Long) numberOfAjaxConnections;
    catch(InterruptedException e)

  • Using Fluent Wait
  • Selenium webdriver provides Fluent wait option to handle uncertain waits. The advantages of this approach is that element polling mechanism is

    FluentWait<By>fluentWait=new FluentWait<By>
    //description of the element for which we want to poll
    //it will ping in every 3 seconds
    fluentWait.until(new Predicate<By>(){
    public boolean apply(By by)
    return browser.findElement(by).isDisplayed();
    catch(NoSuchElement ex)
    return false;

  • Using WebDriver Wait
  • public ExpectedCondition<WebElement>
    visibilityElementLocated(final By by)
    retuen new ExpectedCondition<WebElement>()
    public WebElement apply(WebDriver driver)
    WebElement element=driver.findElement(by);
    return element.isDisplayed()?element:null;
    public void performSomeAction(){
    //your code
    Wait wait=new WebDriverWait(driver,20);
    WebElement element=wait.until(visibilityofElementLocated(By.tagName("a")));

Share and Enjoy !

See also  Learn How to Work with XML with UFT in Fast and Effortless Manner

9 thoughts on “How To Solve Synchronization Failures In Selenium or QTP?

  1. There is obviously a bundle to identify about this. I consider you made some nice points in features also.

  2. Pingback: Google
  3. Pingback: Google
  4. Pingback: Google
  5. Pingback: Google
  6. Pingback: Google
  7. Pingback: Google
  8. Pingback: Google
  9. Ahaa, its good conversation concerning this paragraph at this place at this weblog, I have
    read all that, so now me also commenting at this place.

Leave a Reply

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