Example usage for org.openqa.selenium By tagName

List of usage examples for org.openqa.selenium By tagName

Introduction

In this page you can find the example usage for org.openqa.selenium By tagName.

Prototype

public static By tagName(String tagName) 

Source Link

Usage

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

License:Open Source License

/**
 * Retrieve element by attribute value contains for sub element.
 * @param driver the driver//from   www  .j  av  a  2 s.  co  m
 * @param subElement the sub element
 * @param tagName the tag name
 * @param attributeName the attribute name
 * @param attributeValue the attribute value
 * @param timeOut the time out
 * @return the web element
 */
public static WebElement retrieveElementByAttributeValueContainsForSubElement(final WebDriver driver,
        final WebElement subElement, final String tagName, final String attributeName,
        final String attributeValue, final int timeOut) {

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

            public Boolean apply(WebDriver d) {

                boolean isLoaded = false;
                List<WebElement> elementList = subElement.findElements(By.tagName(tagName));
                for (WebElement webElement : elementList) {
                    String valueAttribute = webElement.getAttribute(attributeName.trim());
                    if (valueAttribute.trim().contains(attributeValue)) {
                        subElementContainsAttrValue = webElement;
                        isLoaded = true;
                        break;
                    }
                }
                return isLoaded;
            }
        });
    } catch (TimeoutException te) {

    }

    return subElementContainsAttrValue;
}

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 .ja  va 2s  . c  o m*/
 * @param rootElement the root element
 * @param tagName the tag name
 * @param attributeName the attribute name
 * @param attributeValue the attribute value
 * @return the web element
 */
public static WebElement retrieveElementByAttributeValueByPassingElement(final WebDriver driver,
        final WebElement rootElement, final String tagName, final String attributeName,
        final String attributeValue) {

    WebElement element = null;
    List<WebElement> elementList = rootElement.findElements(By.tagName(tagName));
    for (WebElement webElement : elementList) {
        String valueAttribute = webElement.getAttribute(attributeName.trim());
        if (valueAttribute.trim().equalsIgnoreCase(attributeValue)) {
            return webElement;
        }
    }

    return element;
}

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

License:Open Source License

/**
 * Retrieve element by tag text./*from   w  w  w .  j a va  2 s  .  com*/
 * @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.//ww w.  j a  va 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./*ww  w . j  a  v  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  .co  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  w w  .ja v  a2 s.  co 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.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);
    }/*from w w w  .  j  a  va 2  s  .co m*/

    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;
}

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

License:Apache License

private By getLocatorBy(final String locator, final LocatorType locatorType) {
    switch (locatorType) {

    case ID:// ww w. ja v a  2 s  . co  m
        return By.id(locator);

    case NAME:
        return By.name(locator);

    case CLASS_NAME:
        return By.className(locator);

    case LINK_TEXT:
        return By.linkText(locator);

    case PARTIAL_LINK_TEXT:
        return By.partialLinkText(locator);

    case CSS_SELECTOR:
        return By.cssSelector(locator);

    case TAG_NAME:
        return By.tagName(locator);

    default:
        return By.xpath(locator);
    }
}