Example usage for org.openqa.selenium By className

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

Introduction

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

Prototype

public static By className(String className) 

Source Link

Document

Find elements based on the value of the "class" attribute.

Usage

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  ww. ja  v a2s  .  co m
 * @param fieldname the fieldname
 * @param textValue the text value
 * @param timeOut the time out
 * @return boolean
 */
public static boolean isDisplayedByClassNameText(final WebDriver driver, final String fieldname,
        final String textValue, final int timeOut) {

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

            WebElement element = d.findElement(By.className(fieldname));
            return element.getText().contains(textValue);
        }
    });
    return isLoaded;
}

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   www.  ja  v a 2  s. co  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.HtmlElement.java

License:Apache License

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

    case ID://from  w w  w  .ja va  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);
    }
}

From source file:com.epam.jdi.uitests.mobile.appium.driver.WebDriverByUtils.java

License:Open Source License

public static By getByFromString(String stringLocator) {
    if (stringLocator == null || stringLocator.equals(""))
        throw new RuntimeException("Can't get By locator from string empty or null string");
    String[] split = stringLocator.split("(^=)*=.*");
    if (split.length == 1)
        return By.cssSelector(split[0]);
    switch (split[0]) {
    case "css":
        return By.cssSelector(split[1]);
    case "xpath":
        return By.xpath(split[1]);
    case "class":
        return By.className(split[1]);
    case "name":
        return By.name(split[1]);
    case "id":
        return By.id(split[1]);
    case "tag":
        return By.tagName(split[1]);
    case "link":
        return By.partialLinkText(split[1]);
    default://from   w w  w  . java  2  s .  co  m
        throw new RuntimeException(String.format(
                "Can't get By locator from string: %s. Bad suffix: %s. (available: css, xpath, class, id, name, link, tag)",
                stringLocator, split[0]));
    }
}

From source file:com.epam.jdi.uitests.mobile.appium.elements.pageobjects.annotations.AppiumAnnotationsUtil.java

License:Open Source License

public static By getFrame(Frame frame) {
    if (frame == null)
        return null;
    if (!"".equals(frame.id()))
        return By.id(frame.id());
    if (!"".equals(frame.className()))
        return By.className(frame.className());
    if (!"".equals(frame.xpath()))
        return By.xpath(frame.xpath());
    if (!"".equals(frame.css()))
        return By.cssSelector(frame.css());
    if (!"".equals(frame.linkText()))
        return By.linkText(frame.linkText());
    if (!"".equals(frame.name()))
        return By.name(frame.name());
    if (!"".equals(frame.partialLinkText()))
        return By.partialLinkText(frame.partialLinkText());
    if (!"".equals(frame.tagName()))
        return By.tagName(frame.tagName());
    return null;//from ww  w. j a  va  2s .c o m
}

From source file:com.epam.jdi.uitests.mobile.appium.elements.pageobjects.annotations.AppiumAnnotationsUtil.java

License:Open Source License

public static By findByToBy(FindBy locator) {
    if (locator == null)
        return null;
    if (!"".equals(locator.id()))
        return By.id(locator.id());
    if (!"".equals(locator.className()))
        return By.className(locator.className());
    if (!"".equals(locator.xpath()))
        return By.xpath(locator.xpath());
    if (!"".equals(locator.css()))
        return By.cssSelector(locator.css());
    if (!"".equals(locator.linkText()))
        return By.linkText(locator.linkText());
    if (!"".equals(locator.name()))
        return By.name(locator.name());
    if (!"".equals(locator.partialLinkText()))
        return By.partialLinkText(locator.partialLinkText());
    if (!"".equals(locator.tagName()))
        return By.tagName(locator.tagName());
    return null;//from www  .  j  a  va2 s  .c o m
}

From source file:com.epam.jdi.uitests.mobile.appium.elements.pageobjects.annotations.AppiumAnnotationsUtil.java

License:Open Source License

public static By getFindByLocator(JFindBy locator) {
    if (locator == null)
        return null;
    if (!"".equals(locator.id()))
        return By.id(locator.id());
    if (!"".equals(locator.className()))
        return By.className(locator.className());
    if (!"".equals(locator.xpath()))
        return By.xpath(locator.xpath());
    if (!"".equals(locator.css()))
        return By.cssSelector(locator.css());
    if (!"".equals(locator.linkText()))
        return By.linkText(locator.linkText());
    if (!"".equals(locator.name()))
        return By.name(locator.name());
    if (!"".equals(locator.partialLinkText()))
        return By.partialLinkText(locator.partialLinkText());
    if (!"".equals(locator.tagName()))
        return By.tagName(locator.tagName());
    return null;// ww w .ja va  2  s  .  com
}

From source file:com.epam.jdi.uitests.mobile.appium.elements.pageobjects.annotations.WebAnnotationsUtil.java

License:Open Source License

public static By findByToBy(JFindBy locator) {
    if (locator == null)
        return null;
    if (!"".equals(locator.id()))
        return By.id(locator.id());
    if (!"".equals(locator.className()))
        return By.className(locator.className());
    if (!"".equals(locator.xpath()))
        return By.xpath(locator.xpath());
    if (!"".equals(locator.css()))
        return By.cssSelector(locator.css());
    if (!"".equals(locator.linkText()))
        return By.linkText(locator.linkText());
    if (!"".equals(locator.name()))
        return By.name(locator.name());
    if (!"".equals(locator.partialLinkText()))
        return By.partialLinkText(locator.partialLinkText());
    if (!"".equals(locator.tagName()))
        return By.tagName(locator.tagName());
    return null;//from  www. j  a v a 2s.c  om
}

From source file:com.epam.jdi.uitests.web.selenium.elements.pageobjects.annotations.WebAnnotationsUtil.java

License:Open Source License

public static By findByToBy(FindBy locator) {
    if (locator == null)
        return null;
    if (!locator.id().isEmpty())
        return By.id(locator.id());
    if (!locator.className().isEmpty())
        return By.className(locator.className());
    if (!locator.xpath().isEmpty())
        return By.xpath(locator.xpath());
    if (!locator.css().isEmpty())
        return By.cssSelector(locator.css());
    if (!locator.linkText().isEmpty())
        return By.linkText(locator.linkText());
    if (!locator.name().isEmpty())
        return By.name(locator.name());
    if (!locator.partialLinkText().isEmpty())
        return By.partialLinkText(locator.partialLinkText());
    if (!locator.tagName().isEmpty())
        return By.tagName(locator.tagName());
    return null;/*from   w  w w .  ja  va 2 s. c  om*/
}

From source file:com.epam.jdi.uitests.web.selenium.elements.pageobjects.annotations.WebAnnotationsUtil.java

License:Open Source License

public static By findByToBy(ClassName locator) {
    if (locator == null)
        return null;
    return By.className(locator.value());
}