Example usage for org.openqa.selenium.support ByIdOrName ByIdOrName

List of usage examples for org.openqa.selenium.support ByIdOrName ByIdOrName

Introduction

In this page you can find the example usage for org.openqa.selenium.support ByIdOrName ByIdOrName.

Prototype

public ByIdOrName(String idOrName) 

Source Link

Usage

From source file:com.raja.anucarita.SeCustomUtils.java

License:Open Source License

public static List<WebElement> elementsReturn(WebDriver driver, String locator) throws Exception {
    byMethod = locator.split("=", 2)[0];
    actualLocator = locator.split("=", 2)[1];

    if (byMethod.equalsIgnoreCase("css")) {
        elements = driver.findElements(By.cssSelector(actualLocator));
    } else if (byMethod.equalsIgnoreCase("jQuery")) {
        /*/*ww  w  .j a  v a 2  s. co  m*/
        Need to write code for iterating multiple elements with jQuery
        */
        String Timeout = values.getProperty("timeout");

        final String LocatorTwo = actualLocator;
        try {
            wait = new WebDriverWait(driver, Integer.parseInt(Timeout));
            wait.until(new ExpectedCondition<Boolean>() {
                public Boolean apply(WebDriver driver) {
                    Result = false;
                    try {
                        element = findElementByjQuery(driver, LocatorTwo);
                        if (element instanceof WebElement) {
                            Result = true;
                        } else {
                            Result = false;
                        }
                    } catch (Exception e) {
                    }
                    return Result;
                }
            });
        } catch (Exception e) {
        }

        element = findElementByjQuery(driver, actualLocator);
        elements.add(element);
        /**/
    } else if (byMethod.equalsIgnoreCase("linkText")) {
        elements = driver.findElements(By.linkText(actualLocator));
    } else if (byMethod.equalsIgnoreCase("id")) {
        elements = driver.findElements(By.id(actualLocator));
    } else if (byMethod.equalsIgnoreCase("name")) {
        elements = driver.findElements(By.name(actualLocator));
    } else if (byMethod.equalsIgnoreCase("ByIDorName")) {
        driver.findElements(new ByIdOrName(actualLocator));
    } else if (byMethod.equalsIgnoreCase("partialLinkText")) {
        elements = driver.findElements(By.partialLinkText(actualLocator));
    } else if (byMethod.equalsIgnoreCase("xpath")) {
        elements = driver.findElements(By.xpath(actualLocator));
    } else {
    }
    return elements;
}

From source file:com.ts.commons.TSPageFactory.TSAnnotations.java

License:Apache License

protected By buildByFromLongFindBy(FindBy findBy) {
    How how = findBy.how();//from   w w  w  . j ava 2 s.  c  o m
    String using = findBy.using();

    switch (how) {
    case CLASS_NAME:
        return (By) By.className(using);

    case CSS:
        return (By) By.cssSelector(using);

    case ID:
        return (By) By.id(using);

    case ID_OR_NAME:
        return (By) ((org.openqa.selenium.By) new ByIdOrName(using));

    case LINK_TEXT:
        return (By) By.linkText(using);

    case NAME:
        return (By) By.name(using);

    case PARTIAL_LINK_TEXT:
        return (By) By.partialLinkText(using);

    case TAG_NAME:
        return (By) By.tagName(using);

    case XPATH:
        return (By) By.xpath(using);

    default:
        // Note that this shouldn't happen (eg, the above matches all
        // possible values for the How enum)
        throw new IllegalArgumentException("Cannot determine how to locate element " + field);
    }
}

From source file:io.github.blindio.prospero.core.utils.BySeleneseLocator.java

License:Apache License

public static By seleneseLocator(String seleneseLocator) throws ProsperoUnsupportedLocatorException {
    By parsedBy = null;/*  ww w. ja v a2s. c  om*/

    int index = seleneseLocator.indexOf(EQUALS_SYMBOL_CODE_POINT);
    String strategy = null;
    String locator = null;
    if (index != -1) {
        strategy = seleneseLocator.substring(0, index);
        locator = seleneseLocator.substring(index + 1);

        if (!(strategy.equalsIgnoreCase(STRATEGY_IDENTIFIER) || strategy.equalsIgnoreCase(STRATEGY_ID)
                || strategy.equalsIgnoreCase(STRATEGY_NAME) || strategy.equalsIgnoreCase(STRATEGY_DOM)
                || strategy.equalsIgnoreCase(STRATEGY_XPATH) || strategy.equalsIgnoreCase(STRATEGY_LINK)
                || strategy.equalsIgnoreCase(STRATEGY_CSS) || strategy.equalsIgnoreCase(STRATEGY_UI))) {
            strategy = null;
        }
    }

    if (strategy == null) {
        locator = seleneseLocator;
        if (seleneseLocator.substring(0, IMPLICIT_STRATEGY_DOM.length()).toLowerCase()
                .equals(IMPLICIT_STRATEGY_DOM)) {
            strategy = STRATEGY_DOM;
        } else if (seleneseLocator.substring(0, IMPLICIT_STRATEGY_XPATH.length())
                .equals(IMPLICIT_STRATEGY_XPATH)) {
            strategy = STRATEGY_XPATH;
        } else {
            strategy = STRATEGY_IDENTIFIER;
        }
    }

    if (strategy.equalsIgnoreCase(STRATEGY_IDENTIFIER)) {
        parsedBy = new ByIdOrName(locator);
    } else if (strategy.equalsIgnoreCase(STRATEGY_ID)) {
        parsedBy = By.id(locator);
    } else if (strategy.equalsIgnoreCase(STRATEGY_NAME)) {
        parsedBy = By.name(locator);
        // TODO: use ByChained to parse element-filters
    } else if (strategy.equalsIgnoreCase(STRATEGY_DOM)) {
        parsedBy = null;
        throw new ProsperoUnsupportedLocatorException("Selenium 1.x Locator Strategy: " + STRATEGY_DOM
                + " is not supported in Webdriver.  Selenium recommend using the " + STRATEGY_XPATH
                + " strategy (" + seleneseLocator + ")");
    } else if (strategy.toLowerCase().equals(STRATEGY_XPATH)) {
        if (locator.endsWith("/")) {
            parsedBy = By.xpath(locator.substring(0, locator.length() - 1));
        } else {
            parsedBy = By.xpath(locator);
        }
    } else if (strategy.equalsIgnoreCase(STRATEGY_LINK)) {
        parsedBy = By.partialLinkText(seleneseLocator);
    } else if (strategy.equalsIgnoreCase(STRATEGY_CSS)) {
        parsedBy = By.cssSelector(locator);
    } else if (strategy.equalsIgnoreCase(STRATEGY_UI)) {
        parsedBy = null;
        throw new ProsperoUnsupportedLocatorException("Selenium 1.x Locator Strategy: " + STRATEGY_UI
                + " is not supported in Webdriver (" + seleneseLocator + ")");
    } else {
        // TODO
    }

    return parsedBy;
}

From source file:net.codestory.simplelenium.reflection.ReflectionUtil.java

License:Apache License

public static void injectMissingElements(Object pageObject) {
    injectMissingPageObjects(pageObject);
    injectNullFieldsOfType(DomElement.class, pageObject,
            field -> new LazyDomElement(new ByIdOrName(field.getName())));
    injectNullFieldsWithConstructorParameterOfType(DomElement.class, pageObject,
            field -> new LazyDomElement(new ByIdOrName(field.getName())));
}

From source file:org.jboss.arquillian.graphene.enricher.findby.Annotations.java

License:Apache License

protected By buildByFromLongFindBy(FindBy findBy) {
    How how = findBy.how();/*from  www.  ja va2 s.c  o m*/
    String using = findBy.using();

    switch (how) {
    case CLASS_NAME:
        return By.className(using);

    case CSS:
        return By.cssSelector(using);

    case ID:
        return By.id(using);

    case ID_OR_NAME:
        return new ByIdOrName(using);

    case LINK_TEXT:
        return By.linkText(using);

    case NAME:
        return By.name(using);

    case PARTIAL_LINK_TEXT:
        return By.partialLinkText(using);

    case TAG_NAME:
        return By.tagName(using);

    case XPATH:
        return By.xpath(using);

    default:
        // Note that this shouldn't happen (eg, the above matches all
        // possible values for the How enum)
        throw new IllegalArgumentException("Cannot determine how to locate element " + field);
    }
}

From source file:org.jboss.arquillian.graphene.enricher.findby.Annotations.java

License:Apache License

private By getByFromGrapheneHow(org.jboss.arquillian.graphene.enricher.findby.How how, String using) {
    switch (how) {
    case CLASS_NAME:
        return By.className(using);

    case CSS:
        return By.cssSelector(using);

    case ID://from   ww  w .  j  a v  a  2  s.c  o  m
        return By.id(using);

    case ID_OR_NAME:
        return new ByIdOrName(using);

    case LINK_TEXT:
        return By.linkText(using);

    case NAME:
        return By.name(using);

    case PARTIAL_LINK_TEXT:
        return By.partialLinkText(using);

    case TAG_NAME:
        return By.tagName(using);

    case XPATH:
        return By.xpath(using);

    case JQUERY:
        return ByJQuery.jquerySelector(using);

    default:
        // Note that this shouldn't happen (eg, the above matches all
        // possible values for the How enum)
        throw new IllegalArgumentException("Cannot determine how to locate element " + field);
    }
}

From source file:org.jboss.arquillian.graphene.findby.Annotations.java

License:Open Source License

private By getByFromHow(How how, String using) {
    switch (how) {
    case CLASS_NAME:
        return By.className(using);

    case CSS:
        return By.cssSelector(using);

    case ID://from   w w  w  .ja  va2s.  co m
        return By.id(using);

    case ID_OR_NAME:
        return new ByIdOrName(using);

    case LINK_TEXT:
        return By.linkText(using);

    case NAME:
        return By.name(using);

    case PARTIAL_LINK_TEXT:
        return By.partialLinkText(using);

    case TAG_NAME:
        return By.tagName(using);

    case XPATH:
        return By.xpath(using);

    default:
        // Note that this shouldn't happen (eg, the above matches all
        // possible values for the How enum)
        throw new IllegalArgumentException("Cannot determine how to locate element " + field);
    }
}

From source file:org.openqa.runner.CommandMappings.java

License:Apache License

public static By detectTargetMethod(String target) {
    if ((target.startsWith("//")) || (target.startsWith("xpath="))) {
        target = target.replace("xpath=", "");
        return By.xpath(target);
    }/*from w  w  w .  j  a v  a  2 s .co m*/

    if (target.startsWith("link=")) {
        target = target.replace("link=", "");
        return By.linkText(target);
    }

    if (target.startsWith("css=")) {
        target = target.replace("css=", "");
        return By.cssSelector(target);
    }

    if (target.startsWith("name=")) {
        target = target.replace("name=", "");
        return By.name(target);
    }

    if ((target.startsWith("dom")) || (target.startsWith("document."))) {
        return new ByDOM(target);
    }

    if (target.startsWith("id=")) {
        target = target.replace("id=", "");
        return By.id(target);
    }

    return new ByIdOrName(target);
}

From source file:webdriver.elements.factory.UIAnnotations.java

License:Apache License

protected By buildByFromDefault() {
    return new ByIdOrName(field.getName());
}