Does Selenium Ajax wait if Ajax doesn't return any elements?

I am sending some keys for some input. When focus is removed from this element, an ajax request is sent to the server if this value is valid. If so, nothing happens if no error message appears. There are a couple of these fields.

When I speak:

driver.findElementById(firstId).sendKeys(firstValue);
driver.findElementById(secondId).sendKeys(secondValue);

The second value will not be sent to the second element, because at that time there will be a very short ajax request. But since the value is in order (firstValue), it will not output text or anything else.

How can I tell Selenium to wait for this ajax to finish? I do not want to use Thread.sleep.

+5
source share
1 answer

AJAX. . AJAX, .

Implicit Wait Explicit Wait, -, . , , .

:

, , , . , .

:

WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(strEdit)));

WebElement myDynamicElement = (new WebDriverWait(driver, 30))
.until(new ExpectedCondition<WebElement>(){
@Override
public WebElement apply(WebDriver d) {
return d.findElement(By.id("myDynamicElement"));
}});

30 , TimeoutException , 0-30 . WebDriverWait ExpectedCondition 500 , . ExpectedCondition - Boolean return true not null ExpectedCondition.

ExpectedConditions , .

:

WebDriver DOM ,

:

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

, , , - WebDriver

http://seleniumhq.org/docs/04_webdriver_advanced.jsp

You can use these waits during your AJAX loading.

, .

+7

All Articles