Example usage for org.openqa.selenium WebElement getText

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

Introduction

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

Prototype

String getText();

Source Link

Document

Get the visible (i.e.

Usage

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

@Override
public void select(String selectLocator, String optionLocator) {
    Select select = new Select(findElement(selectLocator));
    List<WebElement> options = select.getOptions();
    log.debug("options found " + options.size() + " elements");
    String[] locator = optionLocator.split("=");
    log.debug("Locator has " + locator.length + " elements");
    String find;/*from   w w w  .j  ava2  s.  com*/
    if (locator.length > 1) {
        find = locator[1];
    } else {
        find = locator[0];
    }
    log.debug(" find is " + find);
    if (locator[0].contains(VALUE)) {
        log.debug("checking value");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getAttribute(VALUE));
            if (we.getAttribute(VALUE).equals(find)) {
                we.click();
                break;
            }
        }
    } else if (locator[0].contains("id")) {
        log.debug("checking id");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getAttribute("id"));
            if (we.getAttribute("id").equals(find)) {
                we.click();
                break;
            }
        }
    } else if (locator[0].contains("index")) {
        log.debug("checking index");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getAttribute("index"));
            if (we.getAttribute("index").equals(find)) {
                we.click();
                break;
            }
        }
    } else {
        boolean flag = false;
        log.debug("checking text or label, default option");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getText());
            if (we.getText().equals(find)) {
                we.click();
                flag = true;
                break;
            }
        }
        if (flag == false) {
            click(optionLocator);
        }
    }
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

@Override
public boolean isSelectOptionEnable(String selectLocator, String optionLocator) {
    Select select = new Select(findElement(selectLocator));
    List<WebElement> options = select.getOptions();
    log.debug("options found " + options.size() + " elements");
    String[] locator = optionLocator.split("=");
    log.debug("Locator has " + locator.length + " elements");
    String find;/*from  w w  w .j  a  v  a2 s .co m*/
    if (locator.length > 1) {
        find = locator[1];
    } else {
        find = locator[0];
    }
    log.debug(" find is " + find);
    if (locator[0].contains(VALUE)) {
        log.debug("checking value");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getAttribute(VALUE));
            if (we.getAttribute(VALUE).equals(find)) {
                return we.isEnabled();
            }
        }
    } else if (locator[0].contains("id")) {
        log.debug("checking id");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getAttribute("id"));
            if (we.getAttribute("id").equals(find)) {
                return we.isEnabled();
            }
        }
    } else if (locator[0].contains("index")) {
        log.debug("checking index");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getAttribute("index"));
            if (we.getAttribute("index").equals(find)) {
                return we.isEnabled();
            }
        }
    } else {
        log.debug("checking text or label, default option");
        for (WebElement we : options) {
            log.debug("Printing found options: " + we.getText());
            if (we.getText().equals(find)) {
                return we.isEnabled();
            }
        }
    }
    return false;
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

/**
 * selects an item from a dropdown list that contains the parameter stringLike
 *
 * @param guiElementLocator - identifies the dropdown list
 * @param stringLike - string to match in the elements of the dropdown list
 * @return the text name of the "matching" item selected in the dropdown; empty string if no match found
 *///from  w w  w  . j  a va  2  s .c  o  m
@Override
public String selectLikeItemFromDropDown(String guiElementLocator, String stringLike) {
    waitForDropdownPopulated(guiElementLocator);
    List<WebElement> options = getSelectOptions(guiElementLocator);
    Iterator<WebElement> iter = options.iterator();
    while (iter.hasNext()) {
        WebElement el = iter.next();
        String opt = el.getText();
        if (opt.toLowerCase().contains(stringLike.toLowerCase())) {
            selectItemFromDropDown(guiElementLocator, opt);
            log.debug("value as selected in dropdown is " + opt);
            return opt;
        }
    }
    log.warn("Returning empty string, No Service name found in dropdown matching " + stringLike);
    return "";
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

/**
 * if dropdown is a required field, will select from the list, depending on content of parameter item if
 * item is empty, selects random element from the dropdown list if item has content, selects it from the
 * dropdown list if dropdown isn't required field, does nothing
 *
 * @param selectElementLocator - identifies the dropdown list
 * @param item - element to select on the dropdown list
 * @param isRequired - is this a required field
 *//*  w w w  .ja v  a2s . c  o m*/
@Override
public void selectItemFromDropDown(String selectElementLocator, String item, boolean isRequired) {
    if (item == null || item.equals("")) {
        if (isRequired) {
            selectRandomItemFromDropDown(selectElementLocator);
        }
        return;
    }
    waitForDropdownPopulated(selectElementLocator);
    try {
        select(selectElementLocator, item);
    } catch (Exception e) {
        log.warn(item + " not found in the select, finding a good match");
        List<WebElement> options = getSelectOptions(selectElementLocator);
        Iterator<WebElement> iter = options.iterator();
        while (iter.hasNext()) {
            WebElement el = iter.next();
            String opt = el.getText();
            if (opt.contains(item)) {
                select(selectElementLocator, opt);
                return;
            }
        }
        selectItemFromDropDown(selectElementLocator, item);
    }
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

/**
 * selects an item from a dropdown list that starts with the parameter stringStartsWith
 *
 * @param guiElementLocator - identifies the dropdown list
 * @param stringStartsWith - string to match starts with in elements of the dropdown list
 *//*from   w  w w .  ja va  2 s.  c  om*/
@Override
public void selectItemStartWithFromDropDown(String guiElementLocator, String stringStartsWith) {
    waitForDropdownPopulated(guiElementLocator);
    List<WebElement> options = getSelectOptions(guiElementLocator);
    Iterator<WebElement> iter = options.iterator();
    while (iter.hasNext()) {
        WebElement el = iter.next();
        String opt = el.getText();
        if (opt.toLowerCase().startsWith(stringStartsWith.toLowerCase())) {
            selectItemFromDropDown(guiElementLocator, opt);
        }
    }
}

From source file:com.cisco.dbds.utils.selenium.SeleniumUtilities.java

License:Open Source License

/**
 * Retrieves text from web elements and returns them.
 * /*from w  w  w.  j  a  v  a  2  s  .  co m*/
 * @param elements
 *            - List of non null text from given web elements
 * @return the string from web elements
 */
public static List<String> getStringFromWebElements(List<WebElement> elements) {
    List<String> elementStrings = new ArrayList<>();
    for (WebElement webElement : elements) {
        if (webElement != null) {
            String textValue = webElement.getText();
            if (textValue != null) {
                elementStrings.add(textValue);
            }
        }
    }
    return elementStrings;
}

From source file:com.citrix.g2w.webdriver.pages.BasePage.java

License:Open Source License

/**
 * Method to find presence of inner text for the elements in page.
 * Can be used when elements vissibiliy is changed dynamically to make sure
 * that inner text is vissible./*from  w  w  w. j  a va  2s .c om*/
 * @param by
 * @param timeoutInSeconds
 * @return presenceOfElements
 */
public List<WebElement> findPresenceOfInnerTextForElements(final By by, final int timeoutInSeconds) {
    List<WebElement> presenceOfElements;
    final int waitForElement = timeoutInSeconds / 5;
    try {
        presenceOfElements = (new WebDriverWait(this.driver, timeoutInSeconds))
                .until(new ExpectedCondition<List<WebElement>>() {
                    @Override
                    public List<WebElement> apply(WebDriver driver) {
                        try {
                            List<WebElement> elements = findPresenceOfElements(by, waitForElement);
                            for (WebElement element : elements) {
                                if (!StringUtils.hasText(element.getText())) {
                                    return null;
                                }
                            }
                            return elements.size() > 0 ? elements : null;
                        } catch (Throwable e) {
                            return null;
                        }
                    }
                });
    } catch (Exception e) {
        this.logger.logWithScreenShot("Could not find presence of elements: " + by.toString(), this.driver);
        throw new RuntimeException(e);
    }
    return presenceOfElements;
}

From source file:com.citrix.g2w.webdriver.pages.BasePage.java

License:Open Source License

/**
 * Method to return list of titles/get text for the given xpath.
 *
 * @param xpath/*from   www.jav  a  2s .  c  om*/
 *            (xpath of elements)
 * @return List<String> list of titles of WebElements
 */
public List<String> getListOfTitlesForElementsWithGivenXPath(final String xpath) {
    this.logger.log("To get list of existing elements having xpath : " + xpath);
    List<String> listOfWebElementTitle = new ArrayList<String>();
    List<WebElement> listOfElements = (new WebDriverWait(this.driver, 30))
            .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(xpath)));
    for (WebElement element : listOfElements) {
        if (element.getText() != null && element.getText().length() > 0) {
            listOfWebElementTitle.add(element.getText());
        }
    }
    return listOfWebElementTitle;
}

From source file:com.citrix.g2w.webdriver.pages.ManageWebinarPage.java

License:Open Source License

/**
 * Method to get Webinar id of the Webinar.
 * //from   ww w .j a  va 2s  . c  o  m
 * @return Webinar id
 */
public Long getWebinarId() {
    WebElement element = this.driver.findElement(By.xpath("id('registrationURL')/following-sibling::span"));
    String webinarId = element.getText().replaceAll("-", "");
    this.logger.log("Webinar Id:" + webinarId);

    return Long.valueOf(webinarId);
}

From source file:com.citrix.g2w.webdriver.pages.ManageWebinarPage.java

License:Open Source License

/**
 * Gets a webinarID of a specific instance in a recurring webinar series.
 * @param sessionSequence/*  w w  w  .ja v  a 2s  . c  om*/
 * @return webinarID formatted webinar id from the page
 */
public String getSpecificWebinarIDForRecurringWebinar(int sessionSequence) {
    WebElement webinarIDLinkElement = this.driver.findElement(By.id("editDateTime_" + sessionSequence));
    String webinarID = webinarIDLinkElement.getText();
    this.logger.log("Selected webinar id : " + webinarID);
    return webinarID;
}