Example usage for org.openqa.selenium WebElement findElements

List of usage examples for org.openqa.selenium WebElement findElements

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement findElements.

Prototype

@Override
List<WebElement> findElements(By by);

Source Link

Document

Find all elements within the current context using the given mechanism.

Usage

From source file:com.induscorp.prime.testing.ui.standard.domobj.ListBoxValidatorSD.java

License:Open Source License

@Override
public void validateSelectedItem(String expectedSelectedValue, TextValidationMechanism validationMechanism,
        int numRetries) {
    WebElement selectElement = domObjValidator.findElement(numRetries);

    List<WebElement> options = selectElement.findElements(By.xpath("./option"));
    Assert.assertNotNull(options, "Failed to find items for ListBox '" + uiObject.getDisplayName() + "'.");
    Assert.assertTrue(options.size() > 0,
            "Failed to find items in ListBox '" + uiObject.getDisplayName() + "'. Found 0 items.");

    String optionTextValue;//from  www  .j ava 2 s. c om
    boolean found = false;
    for (WebElement option : options) {
        optionTextValue = option.getText();
        if (optionTextValue != null && option.isSelected()
                && matchTextValue(optionTextValue.trim(), expectedSelectedValue, validationMechanism)) {
            found = true;
            break;
        }
    }

    if (!found) {
        Assert.fail("Failed to find selected item '" + expectedSelectedValue + "' in ListBox '"
                + uiObject.getDisplayName() + "'.");
    }
}

From source file:com.induscorp.prime.testing.ui.standard.domobj.ListBoxValidatorSD.java

License:Open Source License

@Override
public String getSelectedItem(int numRetries) {
    WebElement selectElement = domObjValidator.findElement(numRetries);

    List<WebElement> options = selectElement.findElements(By.xpath("./option"));
    Assert.assertNotNull(options, "Failed to find items for ListBox '" + uiObject.getDisplayName() + "'.");
    Assert.assertTrue(options.size() > 0,
            "Failed to find items in ListBox '" + uiObject.getDisplayName() + "'. Found 0 items.");

    String optionTextValue;//from  w w  w  . jav  a  2s .c  o  m
    for (WebElement option : options) {
        optionTextValue = option.getText();
        if (optionTextValue != null && option.isSelected()) {
            return optionTextValue;
        }
    }
    return null;
}

From source file:com.induscorp.prime.testing.ui.standard.domobj.ListBoxValidatorSD.java

License:Open Source License

@Override
public List<String> getSelectedItems(int numRetries) {
    WebElement selectElement = domObjValidator.findElement(numRetries);

    List<WebElement> options = selectElement.findElements(By.xpath("./option"));
    Assert.assertNotNull(options, "Failed to find items for ListBox '" + uiObject.getDisplayName() + "'.");
    Assert.assertTrue(options.size() > 0,
            "Failed to find items in ListBox '" + uiObject.getDisplayName() + "'. Found 0 items.");

    List<String> selectedItems = new LinkedList<String>();
    String optionTextValue;//w ww.j  a v a  2  s  .c  om
    for (WebElement option : options) {
        optionTextValue = option.getText();
        if (optionTextValue != null && option.isSelected()) {
            selectedItems.add(optionTextValue);
        }
    }
    return selectedItems;
}

From source file:com.induscorp.prime.testing.ui.standard.domobj.ListBoxValidatorSD.java

License:Open Source License

@Override
public void selectFirstItem(int numRetries) {
    WebElement selectElement = domObjValidator.findElement(numRetries);

    List<WebElement> options = selectElement.findElements(By.xpath("./option"));
    Assert.assertNotNull(options, "Failed to find items for ListBox '" + uiObject.getDisplayName() + "'.");
    Assert.assertTrue(options.size() > 0,
            "Failed to find items in ListBox '" + uiObject.getDisplayName() + "'. Found 0 items.");

    options.get(0).click();/*from  w  w  w.  jav  a2s. c  o m*/
}

From source file:com.induscorp.prime.testing.ui.standard.domobj.ListBoxValidatorSD.java

License:Open Source License

@Override
public void selectLastItem(int numRetries) {
    WebElement selectElement = domObjValidator.findElement(numRetries);

    List<WebElement> options = selectElement.findElements(By.xpath("./option"));
    Assert.assertNotNull(options, "Failed to find items for ListBox '" + uiObject.getDisplayName() + "'.");
    Assert.assertTrue(options.size() > 0,
            "Failed to find items in ListBox '" + uiObject.getDisplayName() + "'. Found 0 items.");

    options.get(options.size() - 1).click();
}

From source file:com.induscorp.prime.testing.ui.standard.domobj.ListBoxValidatorSD.java

License:Open Source License

@Override
public void selectItem(String itemName, int numRetries) {
    WebElement selectElement = domObjValidator.findElement(numRetries);

    List<WebElement> options = selectElement.findElements(By.xpath("./option"));
    Assert.assertNotNull(options, "Failed to find items for ListBox '" + uiObject.getDisplayName() + "'.");

    String optionTextValue;//from www. j  a v a2  s  .  c o m
    boolean found = false;

    //performAction(new KeyboardEvent(KeyboardEventName.kbKeyUp, Keys.CONTROL, null), 0);
    for (WebElement option : options) {
        optionTextValue = option.getText();
        if (optionTextValue != null && itemName.equals(optionTextValue.trim())) {
            if (!option.isSelected()) {
                option.click();
            }
            found = true;
            //break;
        } else if (option.isSelected()) {
            option.click();
        }
    }

    if (!found) {
        Assert.fail("Failed to find item '" + itemName + "' in ListBox '" + uiObject.getDisplayName() + "'.");
    }
}

From source file:com.induscorp.prime.testing.ui.standard.domobj.ListBoxValidatorSD.java

License:Open Source License

@Override
public void selectItems(ItemList<String> itemsToBeSelected, int numRetries) {
    WebElement selectElement = domObjValidator.findElement(numRetries);

    List<WebElement> options = selectElement.findElements(By.xpath("./option"));
    Assert.assertNotNull(options, "Failed to find items for ListBox '" + uiObject.getDisplayName() + "'.");

    String optionTextValue;/* w  w  w.  ja  v a2 s  . c om*/
    List<String> foundItemList = new LinkedList<String>();
    //int itemNum = 1;      
    for (WebElement option : options) {
        optionTextValue = option.getText();
        if (optionTextValue != null && itemsToBeSelected.getItems().contains(optionTextValue.trim())) {
            try {
                //if(itemNum != 1) {
                //   performAction(new KeyboardEvent(KeyboardEventName.kbKeyDown, Keys.CONTROL, null), 0);
                //}
                option.click();
                foundItemList.add(optionTextValue.trim());
                //if(itemNum != 1) {
                //   performAction(new KeyboardEvent(KeyboardEventName.kbKeyUp, Keys.CONTROL, null), 0);
                //}
            } catch (Throwable th) {
                //if(itemNum != 1) {
                //performAction(new KeyboardEvent(KeyboardEventName.kbKeyUp, Keys.CONTROL, null), 0);
                //}
                throw th;
            }
            //itemNum++;
        }
    }

    if (foundItemList.size() != itemsToBeSelected.size()) {
        itemsToBeSelected.removeAll(foundItemList);
        Assert.fail("Failed to find item(s) '" + itemsToBeSelected + "' in ListBox '"
                + uiObject.getDisplayName() + "'.");
    }
}

From source file:com.induscorp.prime.testing.ui.standard.domobj.ListBoxValidatorSD.java

License:Open Source License

@Override
public void validateItemsPresent(ItemList<String> items, int numRetries) {
    WebElement selectElement = domObjValidator.findElement(numRetries);

    List<WebElement> options = selectElement.findElements(By.xpath("./option"));
    Assert.assertNotNull(options, "Failed to find items for ListBox '" + uiObject.getDisplayName() + "'.");
    Assert.assertTrue(options.size() > 0,
            "Failed to find items in ListBox '" + uiObject.getDisplayName() + "'. Found 0 items.");

    String optionTextValue;//from   ww  w . j a  v  a  2 s  . c  o m
    for (String item : items.getItems()) {
        boolean found = false;
        for (WebElement option : options) {
            optionTextValue = option.getText();
            if (optionTextValue != null && matchTextValue(optionTextValue.trim(), item,
                    TextValidationMechanism.exactMatchWithExpectedValue)) {
                found = true;
                break;
            }
        }

        if (!found) {
            Assert.fail("Failed to find item '" + item + "' in ListBox '" + uiObject.getDisplayName() + "'.");
        }
    }
}

From source file:com.induscorp.prime.testing.ui.standard.domobj.ListBoxValidatorSD.java

License:Open Source License

@Override
public void validateItemsNotPresent(ItemList<String> items, int numRetries) {
    WebElement selectElement = domObjValidator.findElement(numRetries);

    List<WebElement> options = selectElement.findElements(By.xpath("./option"));
    Assert.assertNotNull(options, "Failed to find items for ListBox '" + uiObject.getDisplayName() + "'.");
    Assert.assertTrue(options.size() > 0,
            "Failed to find items in ListBox '" + uiObject.getDisplayName() + "'. Found 0 items.");

    String optionTextValue;/*from   w  ww  . j ava2  s .c  o  m*/
    for (String item : items.getItems()) {
        boolean found = false;
        for (WebElement option : options) {
            optionTextValue = option.getText();
            if (optionTextValue != null && matchTextValue(optionTextValue.trim(), item,
                    TextValidationMechanism.exactMatchWithExpectedValue)) {
                found = true;
                break;
            }
        }

        if (found) {
            Assert.fail("Item '" + item + "' is present in ListBox '" + uiObject.getDisplayName() + "'.");
        }
    }

}

From source file:com.jaeksoft.searchlib.crawler.web.browser.BrowserDriver.java

License:Open Source License

public final List<WebElement> locateBy(WebElement originElement, By by, boolean faultTolerant)
        throws SearchLibException {
    try {/*from w w  w .  j  av  a2s  .  c om*/
        if (originElement == null)
            return null;
        return originElement.findElements(by);
    } catch (Exception e) {
        if (!faultTolerant)
            throw new SearchLibException("Web element location failed: " + by);
        Logging.warn(e);
        return null;
    }
}