Please see the partial code below:
public class OrderDetailsDashboard extends AbstractTestNGSpringContextTests {
By orderDetails = By.cssSelector(".col-md-12 span strong");
By orderMoreDetails = By.cssSelector(".row.panel-info-summary span strong");
By refundOrderButton = By.cssSelector(".refund-order-action");
public orderDetails getOrderDetails(WebDriver driver) {
logger.info("About to collect and returns the specific order details - refreshing page");
WebDriverWait waitForTitle = new WebDriverWait(driver,30);
try {
waitForTitle.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(orderMoreDetails));
}
catch (StaleElementReferenceException ex) {
waitForTitle.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(orderMoreDetails));
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
waitForTitle.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(orderDetails));
I have a problem which it seems to be solved, but I don't satisfied with the solution. I"m trying to load a page with my automation. the next element (represented here as a page object):
By orderDetails = By.cssSelector(".col-md-12 span strong")
is presented 6 times on my page and contains just bold text. I have noticed that when I"m trying to get the 7th element text, I got Index Out Of Bounds Exception
. although i use wait()
method.
In the end I realized that the wait()
is do wait, but not for ALL elements to be resented and this is the reason my test is failed. (this is also the reason I have added the thread.sleep
method).
Is there any way using the wait()
method to actually wait ALL elements on the page?