Example usage for org.openqa.selenium WebDriver findElements

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:beseenium.model.action.findElementsBy.FindElementsByCss.java

License:Open Source License

/**
 * performs the find elements by css action.
 * @param n the index of the element to find information on, i.e. if 3 results are found
 * the 0 will be the first element 1 the second and so on. will get an array out of bounds.
 * If you wish the action to return all of the results found then set n = -1.
 * @return String representation of the returnParam set in the ActionData object
 * passed into the constructor./* w w  w .j  a  va  2s. com*/
 * @throws ActionDataException  
 */
@Override
public String execute(int n) throws ActionDataException {
    String searchParam = super.context.getInputParam();
    WebDriver browser = super.context.getDriver();
    List<WebElement> htmlElements = browser.findElements(By.cssSelector(searchParam));

    super.context.setElement(htmlElements);

    return FormatOutput.formatFindElementOutput(htmlElements, n);
}

From source file:beseenium.model.action.findElementsBy.FindElementsById.java

License:Open Source License

/**
 * performs the find elements by id action.
 * @param n the index of the element to find information on, i.e. if 3 results are found
 * the 0 will be the first element 1 the second and so on. will get an array out of bounds.
 * If you wish the action to return all of the results found then set n = -1.
 * @return String representation of the returnParam set in the ActionData object
 * passed into the constructor./*from w w w. j  a  v a  2  s.  c o  m*/
 * @throws ActionDataException  
 */
@Override
public String execute(int n) throws ActionDataException {
    String searchParam = super.context.getInputParam();
    WebDriver browser = super.context.getDriver();
    List<WebElement> htmlElements = browser.findElements(By.id(searchParam));

    super.context.setElement(htmlElements);

    return FormatOutput.formatFindElementOutput(htmlElements, n);
}

From source file:beseenium.model.action.findElementsBy.FindElementsByLinkTxt.java

License:Open Source License

/**
 * performs the find elements by link text action.
 * @param n the index of the element to find information on, i.e. if 3 results are found
 * the 0 will be the first element 1 the second and so on. will get an array out of bounds.
 * If you wish the action to return all of the results found then set n = -1.
 * @return String representation of the returnParam set in the ActionData object
 * passed into the constructor.//  www  . ja  v  a 2s  .  co m
 * @throws ActionDataException  
 */
@Override
public String execute(int n) throws ActionDataException {
    String searchParam = super.context.getInputParam();
    WebDriver browser = super.context.getDriver();
    List<WebElement> htmlElements = browser.findElements(By.linkText(searchParam));

    super.context.setElement(htmlElements);

    return FormatOutput.formatFindElementOutput(htmlElements, n);
}

From source file:beseenium.model.action.findElementsBy.FindElementsByName.java

License:Open Source License

/**
 * this performs the find elements by name action
 * @param n the index of the element to find information on, i.e. if 3 results are found
 * the 0 will be the first element 1 the second and so on. will get an array out of bounds.
 * If you wish the action to return all of the results found then set n = -1.
 * @return String representation of the returnParam set in the ActionData object
 * passed into the constructor.// ww w  .ja v a2 s .  co m
 * @throws ActionDataException  
 */
@Override
public String execute(int n) throws ActionDataException {
    String searchParam = super.context.getInputParam();
    WebDriver browser = super.context.getDriver();
    List<WebElement> htmlElements = browser.findElements(By.name(searchParam));

    super.context.setElement(htmlElements);
    return FormatOutput.formatFindElementOutput(htmlElements, n);
}

From source file:beseenium.model.action.findElementsBy.FindElementsByPartialLinkTxt.java

License:Open Source License

/**
 * performs the find elements by partial link text action.
 * @param n the index of the element to find information on, i.e. if 3 results are found
 * the 0 will be the first element 1 the second and so on. will get an array out of bounds.
 * If you wish the action to return all of the results found then set n = -1.
 * @return String representation of the returnParam set in the ActionData object
 * passed into the constructor.//  w w  w.ja  va2s.  c o m
 * @throws ActionDataException  
 */
@Override
public String execute(int n) throws ActionDataException {
    String searchParam = super.context.getInputParam();
    WebDriver browser = super.context.getDriver();
    List<WebElement> htmlElements = browser.findElements(By.partialLinkText(searchParam));

    super.context.setElement(htmlElements);

    return FormatOutput.formatFindElementOutput(htmlElements, n);
}

From source file:beseenium.model.action.findElementsBy.FindElementsByTagName.java

License:Open Source License

/**
 * performs the find elements by tag name action
 * @param n the index of the element to find information on, i.e. if 3 results are found
 * the 0 will be the first element 1 the second and so on. will get an array out of bounds.
 * If you wish the action to return all of the results found then set n = -1.
 * @return String representation of the returnParam set in the ActionData object
 * passed into the constructor.//from   w w w. jav a 2  s. c  o m
 * @throws ActionDataException  
 */
@Override
public String execute(int n) throws ActionDataException {
    String searchParam = super.context.getInputParam();
    WebDriver browser = super.context.getDriver();
    List<WebElement> htmlElements = browser.findElements(By.tagName(searchParam));

    super.context.setElement(htmlElements);

    return FormatOutput.formatFindElementOutput(htmlElements, n);
}

From source file:beseenium.model.action.findElementsBy.FindElementsByXpath.java

License:Open Source License

/**
 * performs the find elements by xpath action
 * @param n the index of the element to find information on, i.e. if 3 results are found
 * the 0 will be the first element 1 the second and so on. will get an array out of bounds.
 * If you wish the action to return all of the results found then set n = -1.
 * @return String representation of the returnParam set in the ActionData object
 * passed into the constructor.//w ww . ja  v a  2  s  . c o m
 * @throws ActionDataException  
 */
@Override
public String execute(int n) throws ActionDataException {
    String searchParam = super.context.getInputParam();
    WebDriver browser = super.context.getDriver();
    List<WebElement> htmlElements = browser.findElements(By.xpath(searchParam));

    super.context.setElement(htmlElements);

    return FormatOutput.formatFindElementOutput(htmlElements, n);
}

From source file:bg.pragmatic.lecture13mvn.waits.utils.WaitTool.java

License:Open Source License

/**
 * Wait for the List<WebElement> to be present in the DOM, regardless of
 * being displayed or not. Returns all elements within the current page DOM.
 * //from  www  . ja va 2 s.  c  o  m
 * @param WebDriver
 *            The driver object to be used
 * @param By
 *            selector to find the element
 * @param int The time in seconds to wait until returning a failure
 * 
 * @return List<WebElement> all elements within the current page DOM, or
 *         null (if the timeout is reached)
 */
public static List<WebElement> waitForListElementsPresent(WebDriver driver, final By by, int timeOutInSeconds) {
    List<WebElement> elements;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify
        // implicitlyWait()

        WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
        wait.until((new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver driverObject) {
                return areElementsPresent(driverObject, by);
            }
        }));

        elements = driver.findElements(by);
        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset
        // implicitlyWait
        return elements; // return the element
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:bg.pragmatic.myautomationframework.utils.WaitTool.java

License:Open Source License

/**
 * Wait for the List<WebElement> to be present in the DOM, regardless of
 * being displayed or not. Returns all elements within the current page DOM.
 * /* w  w  w . j av a  2s  .c  om*/
 * @param WebDriver
 *            The driver object to be used
 * @param By
 *            selector to find the element
 * @param int The time in seconds to wait until returning a failure
 * 
 * @return List<WebElement> all elements within the current page DOM, or
 *         null (if the timeout is reached)
 */
public static List<WebElement> waitForListElementsPresent(WebDriver driver, final By by, int timeOutInSeconds) {
    List<WebElement> elements;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify
        // implicitlyWait()

        WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
        wait.until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver driverObject) {
                return areElementsPresent(driverObject, by);
            }
        });

        elements = driver.findElements(by);
        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset
        // implicitlyWait
        return elements; // return the element
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:br.com.mundotigre.scripts.WaitTool.java

License:Open Source License

/**
* Wait for the List<WebElement> to be present in the DOM, regardless of being displayed or not.
* Returns all elements within the current page DOM. 
* 
* @param WebDriver   The driver object to be used 
* @param By   selector to find the element
* @param int   The time in seconds to wait until returning a failure
*
* @return List<WebElement> all elements within the current page DOM, or null (if the timeout is reached)
*/// ww  w. j  a va  2  s . c  o  m
public static List<WebElement> waitForListElementsPresent(WebDriver driver, final By by, int timeOutInSeconds) {
    List<WebElement> elements;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() 

        WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
        wait.until((new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver driverObject) {
                return areElementsPresent(driverObject, by);
            }
        }));

        elements = driver.findElements(by);
        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait
        return elements; //return the element   
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}