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.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * <b> verify the particular value is displayed according to the attribute</b>
 *///from   w  w w  . ja  v  a  2  s.  c  o m
public static WebElement retrieveElementByTagTextForSubElement(final WebDriver driver,
        final WebElement subElement, final String tagName, final String textValue) {

    WebElement element = null;
    List<WebElement> elementList = subElement.findElements(By.tagName(tagName));

    for (WebElement webElement : elementList) {
        String value = webElement.getText().trim();

        if (value.trim().equalsIgnoreCase(textValue))
            return webElement;
    }

    return element;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * <b> verify the particular value is displayed according to the attribute</b>.
 * @param driver the driver//  w  w w.j a va  2  s .c  om
 * @param idValue the id value
 * @param textValue the text value
 * @return the web element
 */
public static WebElement retrieveElementByIdText(final WebDriver driver, final String idValue,
        final String textValue) {

    WebElement element = null;
    List<WebElement> elementList = driver.findElements(By.id(idValue));
    for (WebElement webElement : elementList) {
        String value = webElement.getText();
        if (value.trim().equalsIgnoreCase(textValue))
            return webElement;
    }

    return element;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Retrieve element by tag text.// ww  w.j  a v a 2s . c om
 * @param driver the driver
 * @param tagName the tag name
 * @param textValue the text value
 * @param timeOut the time out
 * @return the web element
 */
public static WebElement retrieveElementByTagText(final WebDriver driver, final String tagName,
        final String textValue, final int timeOut) {

    elementTagText = null;
    (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver d) {

            boolean isLoaded = false;
            List<WebElement> elementList = driver.findElements(By.tagName(tagName));
            for (WebElement webElement : elementList) {
                String value = webElement.getText();
                if (value.trim().equalsIgnoreCase(textValue)) {
                    elementTagText = webElement;
                    isLoaded = true;
                    break;
                }
            }
            return isLoaded;
        }
    });

    /*
     * WebElement element = null; List<WebElement> elementList =
     * driver.findElements(By.tagName(tagName)); for (WebElement webElement : elementList) {
     * String value = webElement.getText(); if(value.trim().equalsIgnoreCase(textValue)) return
     * webElement; }
     */

    return elementTagText;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Contains by tag text.//from  ww  w. j  a v a 2  s  . c  o  m
 * @param driver the driver
 * @param tagName the tag name
 * @param textValue the text value
 * @param timeOut the time out
 * @return the web element
 */
public static WebElement containsByTagText(final WebDriver driver, final String tagName, final String textValue,
        final int timeOut) {

    elementTagText = null;
    (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver d) {

            boolean isLoaded = false;
            List<WebElement> elementList = driver.findElements(By.tagName(tagName));
            for (WebElement webElement : elementList) {
                String value = webElement.getText();
                if (value.trim().contains(textValue)) {
                    elementTagText = webElement;
                    isLoaded = true;
                    break;
                }
            }
            return isLoaded;
        }
    });

    /*
     * WebElement element = null; List<WebElement> elementList =
     * driver.findElements(By.tagName(tagName)); for (WebElement webElement : elementList) {
     * String value = webElement.getText(); if(value.trim().equalsIgnoreCase(textValue)) return
     * webElement; }
     */

    return elementTagText;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Retrieve element by tag text./*from w w  w . jav  a 2s .c o  m*/
 * @param driver the driver
 * @param tagName the tag name
 * @param textValue the text value
 * @return the web element
 */
public static WebElement retrieveElementByTagText(final WebDriver driver, final String tagName,
        final String textValue) {

    WebElement element = null;
    List<WebElement> elementList = driver.findElements(By.tagName(tagName));
    for (WebElement webElement : elementList) {
        String value = webElement.getText();
        if (value.trim().equalsIgnoreCase(textValue))
            return webElement;
    }

    return element;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Retrieve elements by tag text./*from  w w  w.j a  v a 2 s  .  c  o m*/
 * @param driver the driver
 * @param tagName the tag name
 * @param textValue the text value
 * @return the list
 */
public static List<WebElement> retrieveElementsByTagText(final WebDriver driver, final String tagName,
        final String textValue) {

    List<WebElement> elementList = driver.findElements(By.tagName(tagName));
    List<WebElement> listElement = new ArrayList<WebElement>();

    for (WebElement webElement : elementList) {
        String valueAttribute = webElement.getText();
        if (valueAttribute.trim().equalsIgnoreCase(textValue))
            listElement.add(webElement);
    }

    return listElement;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Retrieve sub element by tag text.//from   w ww  .j  a  v  a2s.  c  o  m
 * @param driver the driver
 * @param subElelement the sub elelement
 * @param tagName the tag name
 * @param textValue the text value
 * @param timeOut the time out
 * @return the web element
 */
public static WebElement retrieveSubElementByTagText(final WebDriver driver, final WebElement subElelement,
        final String tagName, final String textValue, final int timeOut) {

    elementTagText = null;
    (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver d) {

            boolean isLoaded = false;
            List<WebElement> elementList = subElelement.findElements(By.tagName(tagName));
            for (WebElement webElement : elementList) {
                String value = webElement.getText();
                if (value.trim().equalsIgnoreCase(textValue)) {
                    elementTagText = webElement;
                    isLoaded = true;
                    break;
                }
            }
            return isLoaded;
        }
    });

    /*
     * WebElement element = null; List<WebElement> elementList =
     * driver.findElements(By.tagName(tagName)); for (WebElement webElement : elementList) {
     * String value = webElement.getText(); if(value.trim().equalsIgnoreCase(textValue)) return
     * webElement; }
     */

    return elementTagText;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Utility to check weather the particular field is displayed by css class name.
 * @param driver the driver/*from  w w w . ja  v a 2s. c  o  m*/
 * @param fieldname the fieldname
 * @param textValue the text value
 * @param textValue2 the text value2
 * @param timeOut the time out
 * @return boolean
 */
public static boolean isDisplayedByClassNameForWeeklySchedule(final WebDriver driver, final String fieldname,
        final String textValue, final String textValue2, final int timeOut) {

    boolean isLoaded = false;
    isLoaded = (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {

            boolean outcome = false;
            WebDriverWait wait = new WebDriverWait(driver, timeOut);
            wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className(fieldname)));

            WebElement element = d.findElement(By.className(fieldname));

            if (element.getText().contains(textValue) || element.getText().contains(textValue2)) {
                outcome = true;
            }
            return outcome;
        }
    });
    return isLoaded;
}

From source file:com.elastica.webelements.BasePage.java

License:Apache License

private String getBodyText() {
    WebElement body = driver.findElement(By.tagName("body"));
    return body.getText();
}

From source file:com.elastica.webelements.BasePage.java

License:Apache License

public boolean isTextPresent(final String text) {
    CustomAssertion.assertNotNull(text, "isTextPresent: text should not be null!");
    driver = WebUIDriver.getWebDriver();

    WebElement body = driver.findElement(By.tagName("body"));

    if (WebUIDriver.getWebUXDriver().getBrowser().equalsIgnoreCase(BrowserType.HtmlUnit.getBrowserType())) {
        return body.getText().contains(text);
    }// w  w  w.  j a  v  a  2 s .c om

    Boolean result = false;

    if (body.getText().contains(text)) {
        return true;
    }

    JavascriptLibrary js = new JavascriptLibrary();
    String script = js.getSeleniumScript("isTextPresent.js");

    result = (Boolean) ((JavascriptExecutor) driver).executeScript("return (" + script + ")(arguments[0]);",
            text);

    // Handle the null case
    return Boolean.TRUE == result;
}