TestProject Forum
Powered by leading experts in the test automation community

Wait for ajax call to complete with Selenium

I’m running tests in selenium on a UI that uses Ajax calls.

Is is possible to make the driver wait until the ajax call can complete ?

e.g.:

WebElement button = driver.findElement(By.xpath("//button[contains(@class, 'ui-button')]"));

button.click();   //clicking the button triggers ajax call that will fill div with html content

Assert.isNotEmpty(driver.findElement(By.Id("containerDiv")).Text);
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("containerDiv")));