1

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?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Nimrod_G
  • 871
  • 1
  • 6
  • 6
  • "the next element [...] is presented 6 times on my page" If there *are* 6 of them on the page and you try to get the 7th element then yes, you are going to have an exception. Did you mean to say that although Selenium *finds* 6, there are in fact *more* than 6? – Louis Sep 02 '14 at 16:14
  • When the page is up, there are 7 elements with the same class name and i"m trying to deal with the last one of them (the 7th). this is why i"m using the wait() method, just here it waits only for the visibility of the first elements, so when i"m trying to apply to the 7th element i get an exception. this is why i used the thread.sleep. My question is if there is any way to tell selenium actually wait for all elements with the same class name of the page. – Nimrod_G Sep 03 '14 at 08:30

1 Answers1

-1

You could wait for any condition, so I guess for list of element to be of expected size.

Did you try findElementsBy() ???

SkorpEN
  • 2,491
  • 1
  • 22
  • 28