Zvika Nadav Zvika Nadav - 1 year ago 107
Javascript Question

Waiting for a table to load completely using selenium WD with java

Is there a way to wait for a table to load completely using selenium with java?
In my case it looks like the tables loaded using ajax and/or jquery.
So far the only possible solution i could find it so put a simply timeout/pause in a milliseconds.
I'm looking for more advanced solution and not hard-coded one.

Answer Source

Selenium provides WebDriverWait with ExpectedConditions.visibilityOfElementLocated to wait for element visible on the DOM. You should try as below :-

WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement el = wait.until(ExpectedConditions.visibilityOfElementLocated(By...));

Note :- Here you can provide By locator as .id(),.className(), .xpath(), .cssSelector() etc.. of your table element. It will wait for 30 seconds to check visibilty of your table on the DOM.

It will throw TimeoutException exception if element will not be visible within 30 seconds.

For eg :- if you want to check visibility of your table with the id, you just run as wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("your table id")));

You can increase the time also..

Hope it will help you..:)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download