Wait for an Ajax call to complete with Selenium 2 WebDriver
var wait = new WebDriverWait(d, TimeSpan.FromSeconds(5));
var element = wait.Until(driver => driver.FindElement(By.Id("Hobbies")));
PHP webdriver wait for Ajax to finish executing
If you are doing AJAX requests using jQuery, you can use this:
$driver->wait()->until(
function ($driver) {
return $driver->executeScript('return jQuery.active === 0;');
}
);
How to wait until all ajax requests are complete in Selenium IDE?
The answer turned out to be rather simple - all you have to do is check the number of active requests (selenium.browserbot.getUserWindow().$.active) with the waitForEval command, and set the value to 0 - and it all happens in the ide.
Selenium wait for AJAX request to finish after button click
As far as I could understand, probably you are waiting for an update to a table data. If so, then first count the number of rows before submitting any data. And again, check for if the table data is increased or not.
int numberCountBeforeTableLoad = driver.findElements(By.cssSelector("your table rows locator")).size();//count row number of your desired table before submitting data
//here submit your data and wait until your table loads with a row count more than previous row count
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.numberOfElementsToBeMoreThan(By.cssSelector("your table rows locator"), numberCountBeforeTableLoad));
Python 3.6.2/Selenium 2.0/AJAX - How to wait for script to conclude server request
if you have jquery on the page, you can define the button with jquery
and wait until the event function is ready.
for your question:
driver.execute_script('button = $("#div_39_1_3");')
events = driver.execute_script('return $._data(button[0],
"events");')
now you need to wait until events variable is not none.
Selenium wait.until to check ajax request finished is throw error
You need to pass a callable to wait.until()
:
wait.until(lambda driver: driver.execute_script("return jQuery.active == 0"))
webdriver wait for ajax request in python
You indeed can add an explicit wait for the presence of an element like
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
ff = webdriver.Firefox()
ff.get("http://somedomain/url_that_delays_loading")
ff.find_element_by_xpath("//div[@class='searchbox']/input").send_keys("obama")
try:
element = WebDriverWait(ff, 10).until(EC.presence_of_element_located((By.ID, "keywordSuggestion")))
finally:
ff.find_element_by_xpath("//div[@class='searchbox']/input").send_keys(Keys.RETURN)
ff.quit()
See: http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#explicit-and-implicit-waits
Selenium wait for Ajax content to load - universal approach
You need to wait for Javascript and jQuery to finish loading. Execute Javascript to check if jQuery.active
is 0
and document.readyState
is complete
, which means the JS and jQuery load is complete.
public boolean waitForJSandJQueryToLoad() {
WebDriverWait wait = new WebDriverWait(driver, 30);
// wait for jQuery to load
ExpectedCondition<Boolean> jQueryLoad = new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
try {
return ((Long)((JavascriptExecutor)getDriver()).executeScript("return jQuery.active") == 0);
}
catch (Exception e) {
// no jQuery present
return true;
}
}
};
// wait for Javascript to load
ExpectedCondition<Boolean> jsLoad = new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor)getDriver()).executeScript("return document.readyState")
.toString().equals("complete");
}
};
return wait.until(jQueryLoad) && wait.until(jsLoad);
}
How to get selenium to wait for ajax response?
I would use
waitForElementPresent(locator)
This will wait until the element is present in the DOM.
If you need to check the element is visible, you may be better using
waitForElementHeight(locator)
Related Topics
How to Reduce Memory Consumption of PDFptable with Many Cells
What's a Good Way of Doing String Templating in .Net
Why Are Some Members Missing When Trying to Print an Object by Serializing to JSON
Static Property Using Inotifypropertychanged. C#
How to Make Chrome Headless After I Login Manually
How to Implement Custom Authentication in ASP.NET MVC 5
How to Solve Circular Reference
How to Set Attributes Values Using Reflection
How to Extract Subscript/Superscript Properly from a PDF Using Itextsharp
What Is Meant by "Managed" VS "Unmanaged" Resources in .Net
Visual Studio Designer in X64 Doesn't Work
Best Way to Handle Integer Overflow in C#
The Application Called an Interface That Was Marshalled for a Different Thread - Windows Store App