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.comcast.dawg.house.pages.IndexPage.java

License:Apache License

/**
 * Return the tag cloud element.//from ww  w. j  a  v a 2s  .  co  m
 *
 * @return  tag cloud element text.
 */
public String getTagCloudElementText() {
    WebElement element = driver.findElement(By.id(TAG_CLOUD_ID));

    return element.getText();
}

From source file:com.comcast.dawg.house.pages.ModelPage.java

License:Apache License

/**
 * Return the list of capabilities already available on loaded model overlay.
 *
 * @return  the list of capabilities./*  w  w w.  ja v  a2  s . c  o  m*/
 */
public List<String> getAllCapabilityNamesOnAlreadyLoadedModelOverlay() {
    List<String> capabilityList = new ArrayList<String>();
    WebElement capabilityListDiv = driver.findElement(By.id(CAPABILITY_LIST_DIV_ID));

    for (WebElement divCapability : capabilityListDiv.findElements(By.tagName(DIV_TAG_NAME))) {
        capabilityList.add(divCapability.getText());
    }

    return capabilityList;
}

From source file:com.comcast.dawg.house.pages.ModelPage.java

License:Apache License

/**
 * Provides the list of family names available on model overlay page.
 *
 * @return  List of all already listed family names on model dialog box.
 *//* w  w  w  . j ava 2s.  c o m*/
public List<String> getAllFamilyNamesOnAlreadyLoadedModelOverlay() {
    List<String> familyNames = new ArrayList<String>();

    for (WebElement familyOptionElement : getAllFamilyOptionElementsOnAlreadyLoadedModelOverlay()) {
        familyNames.add(familyOptionElement.getText());
    }

    return familyNames;
}

From source file:com.comcast.dawg.house.pages.ModelPage.java

License:Apache License

/**
 * Provides the list of model names available on the model configuration page.
 *
 * @return  list of model names./*  w  ww.  ja v a  2s  . c  o m*/
 */
public List<String> getAllModelNames() {
    String modelName = null;
    List<String> modelNames = new ArrayList<String>();

    for (WebElement element : getAllModelNameElements()) {
        modelName = element.getText();
        modelNames.add(modelName);
    }

    return modelNames;
}

From source file:com.comcast.dawg.house.pages.ModelPage.java

License:Apache License

/**
 * Provides the capabilities available for the stb model.
 *
 * @param   modelName  Model name./* w  w w . j a v  a 2 s.  c  o  m*/
 *
 * @return  capabilities of the STB model.
 */
public String getCapabilitiesOfStbModel(String modelName) {
    WebElement modelCapabiliyElement = getStbModelTrElement(modelName)
            .findElement(By.className(MODEL_CAPABILITIES_TD_IDENTIFIER));

    return modelCapabiliyElement.getText();
}

From source file:com.comcast.dawg.house.pages.ModelPage.java

License:Apache License

/**
 * Provides the family of stb model./*from   w  w  w .ja  v  a 2s . co m*/
 *
 * @param   modelName  Model name.
 *
 * @return  family of the STB model.
 */
public String getFamilyOfStbModel(String modelName) {
    WebElement modelFamilyElement = getStbModelTrElement(modelName)
            .findElement(By.className(MODEL_FAMILY_TD_IDENTIFIER));

    return modelFamilyElement.getText();
}

From source file:com.common.ExpectedConditions.java

License:Apache License

/**
 * An expectation for checking if the given text is present in the specified element.
 *
 * @param element the WebElement//from  w  ww  .java  2 s  . c  om
 * @param text to be present in the element
 * @return true once the element contains the given text
 */
public static ExpectedCondition<Boolean> textToBePresentInElement(final WebElement element, final String text) {

    return new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            try {
                String elementText = element.getText();
                return elementText.contains(text);
            } catch (StaleElementReferenceException e) {
                return null;
            }
        }

        @Override
        public String toString() {
            return String.format("text ('%s') to be present in element %s", text, element);
        }
    };
}

From source file:com.company.components.impl.LanguageMenuImpl.java

License:Apache License

@Override
public List<String> getLanguages() {

    expand(); // Selenium won't see invisible elements

    List<String> languages = new ArrayList<String>();
    for (WebElement item : getLanguageItems()) {
        languages.add(item.getText());
    }//from   w w  w. j  a  va2 s .co m

    return languages;
}

From source file:com.consol.citrus.selenium.action.ExtractAction.java

License:Apache License

@Override
public void doExecute(TestContext context) {
    super.doExecute(context);

    if (elements != null) {
        for (By by : elements.keySet()) {
            String variable = elements.get(by).getVariable();
            String attribute = elements.get(by).getAttribute();
            String value = null;//from w  w w  . j  ava  2s.  c o m
            logger.info("extracting the element by <{}>", by);

            WebElement element = webClient.findElement(by);

            // check if the by has attribute selection
            if (by instanceof By.ByXPath) {
                // TODO: refactor the following
                String xpathExpression = by.toString().replaceAll("By.xpath:\\s*", "");
                if (xpathExpression.contains("/@")) {
                    // we found attribute selection.
                    String[] parts = xpathExpression.split("/@");
                    attribute = parts[1];
                    String newXpathExpresseion = parts[0];
                    element = webClient.findElement(By.xpath(newXpathExpresseion));
                }
            }

            if (element != null) {
                if (StringUtils.hasText(attribute)) {
                    value = element.getAttribute(attribute);
                } else {
                    value = element.getAttribute("value");
                    if (StringUtils.isEmpty(value)) {
                        value = element.getText();
                    }
                }
            }
            context.setVariable(variable, value);
        }
    }

    if (StringUtils.hasText(pageName)) {
        WebPage pageObj;
        try {
            logger.debug("Initializing the page object {}", pageName);
            Class pageClass = Class.forName(pageName);
            pageObj = webClient.createPage(pageClass);
            logger.debug("page object {} is succesfully created.", pageName);
            webClient.verifyPage(pageObj);
            for (String pageAction : pageActions.keySet()) {
                String variable = pageActions.get(pageAction);
                logger.debug("running the action {} on the page object {}", pageAction, pageName);
                logger.info("Invoking method '" + pageAction + "' on instance '" + pageClass + "'");
                Method actionMethod = pageObj.getClass().getMethod("get" + pageAction);
                String value = (String) actionMethod.invoke(pageObj);
                context.setVariable(variable, value);
            }
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            throw new CitrusRuntimeException(ex);
        }
    }
}

From source file:com.consol.citrus.selenium.action.ValidateAction.java

License:Apache License

@Override
public void doExecute(TestContext context) {
    super.doExecute(context);
    if (validations != null) {
        for (By by : validations.keySet()) {
            String controlValue = validations.get(by);
            if (ValidationMatcherUtils.isValidationMatcherExpression(controlValue)) {
                String actualValue = null;
                WebElement element = webClient.findElement(by);

                String attribute = null;
                // check if the by has attribute selection
                if (by instanceof By.ByXPath) {
                    // TODO: refactor the following
                    String xpathExpression = by.toString().replaceAll("By.xpath:\\s*", "");
                    if (xpathExpression.contains("/@")) {
                        // we found attribute selection.
                        String[] parts = xpathExpression.split("/@");
                        attribute = parts[1];
                        String newXpathExpresseion = parts[0];
                        element = webClient.findElement(By.xpath(newXpathExpresseion));
                    }/*from  w w w .  j  av a 2  s. co  m*/
                }

                if (element != null) {
                    if (attribute != null) {
                        actualValue = element.getAttribute(attribute);
                    } else {
                        actualValue = element.getAttribute("value");
                        if (actualValue == null || actualValue.isEmpty()) {
                            actualValue = element.getText();
                        }
                    }
                }
                ValidationMatcherUtils.resolveValidationMatcher(by.toString(), actualValue, controlValue,
                        context);
            } else {
                webClient.validate(by, controlValue, null);
            }
        }
    }

    if (StringUtils.hasText(pageName)) {
        WebPage pageObj;
        try {
            logger.debug("Initializing the page object {}", pageName);
            Class pageClass = Class.forName(pageName);
            pageObj = webClient.createPage(pageClass);
            logger.debug("page object {} is succesfully created.", pageName);
            webClient.verifyPage(pageObj);
            for (String pageAction : pageValidations.keySet()) {
                String controlValue = pageValidations.get(pageAction);
                logger.debug("running the action {} on the page object {}", pageAction, pageName);
                logger.info("Invoking method '" + pageAction + "' on instance '" + pageClass + "'");
                Method actionMethod = pageObj.getClass().getMethod("get" + pageAction);
                String actualValue = (String) actionMethod.invoke(pageObj);
                if (ValidationMatcherUtils.isValidationMatcherExpression(controlValue)) {
                    ValidationMatcherUtils.resolveValidationMatcher(pageAction, actualValue, controlValue,
                            context);
                } else {
                    webClient.validate(actualValue, controlValue, null);
                }
            }
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            throw new CitrusRuntimeException(ex);
        }
    }
}