Synchronisation issue in handling dynamic webtable

43 Views Asked by At

I have a simple webtable called branch which has columns id, branchName, BranchLocaction. Ihave to scenarios to add one branch and test if it is correctly added or not. I have the below function which is supposed to give me the latest id before addition and after addition. before addition its invoked properly and gives me the correct row. But afteradding, some times it gives the old id, sometimes correctly new id, sometimes null. Its a definitely wait isssue. I am also calling some customized functions to wait for ajax call/jquery. But still it does not help. Please help me. If you need more detail. PLease let me know

    public int getlatestBranchtID() throws InterruptedException
{


    int totalnoOfrows = driver.findElements(By.xpath("//table[@class='table table-striped']/tbody/tr")).size();
    System.out.println(totalnoOfrows);
    if (totalnoOfrows == 0)
    {
        return Integer.parseInt("0");
    }
    else{
        String latestBranchID= driver.findElements(By.xpath("//table[@class='table table-striped']/tbody/tr/td[1]")).get(totalnoOfrows-1).getText();
        System.out.println("latest branch id is" + latestBranchID);
        return Integer.parseInt(latestBranchID);
    }

}
0

There are 0 best solutions below