Example usage for org.openqa.selenium By partialLinkText

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

Introduction

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

Prototype

public static By partialLinkText(String partialLinkText) 

Source Link

Usage

From source file:org.mozilla.zest.core.v1.ZestClientElement.java

License:Mozilla Public License

protected WebElement getWebElement(ZestRuntime runtime) throws ZestClientFailException {

    WebDriver wd = runtime.getWebDriver(this.getWindowHandle());

    if (wd == null) {
        throw new ZestClientFailException(this, "No client: " + runtime.getVariable(getWindowHandle()));
    }/*from w  w  w  . j a v  a  2  s  .c  o m*/
    String elem = runtime.replaceVariablesInString(this.getElement(), false);

    try {
        if ("className".equalsIgnoreCase(type)) {
            return wd.findElement(By.className(elem));
        } else if ("cssSelector".equalsIgnoreCase(type)) {
            return wd.findElement(By.cssSelector(elem));
        } else if ("id".equalsIgnoreCase(type)) {
            return wd.findElement(By.id(elem));
        } else if ("linkText".equalsIgnoreCase(type)) {
            return wd.findElement(By.linkText(elem));
        } else if ("name".equalsIgnoreCase(type)) {
            return wd.findElement(By.name(elem));
        } else if ("partialLinkText".equalsIgnoreCase(type)) {
            return wd.findElement(By.partialLinkText(elem));
        } else if ("tagName".equalsIgnoreCase(type)) {
            return wd.findElement(By.tagName(elem));
        } else if ("xpath".equalsIgnoreCase(type)) {
            return wd.findElement(By.xpath(elem));
        }
        throw new ZestClientFailException(this, "Unsupported type: " + type);
    } catch (Exception e) {
        throw new ZestClientFailException(this, e);
    }
}

From source file:org.mozilla.zest.core.v1.ZestExpressionClientElementExists.java

License:Mozilla Public License

@Override
public boolean isTrue(ZestRuntime runtime) {
    WebDriver wd = runtime.getWebDriver(this.getWindowHandle());

    if (wd == null) {
        return false;
    }//from w  w w  . jav  a 2s .  c  om
    String elem = runtime.replaceVariablesInString(this.getElement(), false);
    By by = null;

    if ("className".equalsIgnoreCase(type)) {
        by = By.className(elem);
    } else if ("cssSelector".equalsIgnoreCase(type)) {
        by = By.cssSelector(elem);
    } else if ("id".equalsIgnoreCase(type)) {
        by = By.id(elem);
    } else if ("linkText".equalsIgnoreCase(type)) {
        by = By.linkText(elem);
    } else if ("name".equalsIgnoreCase(type)) {
        by = By.name(elem);
    } else if ("partialLinkText".equalsIgnoreCase(type)) {
        by = By.partialLinkText(elem);
    } else if ("tagName".equalsIgnoreCase(type)) {
        by = By.tagName(elem);
    } else if ("xpath".equalsIgnoreCase(type)) {
        by = By.xpath(elem);
    } else {
        return false;
    }

    return wd.findElements(by).size() > 0;
}

From source file:org.mozilla.zest.core.v1.ZestLoopTokenClientElementsSet.java

License:Mozilla Public License

/**
 * private method for initialization of the loop (TokenSet & first state).
 *
 * @return the zest loop token string set
 * @throws ZestClientFailException /*from www . j a  va2  s . c om*/
 */
protected ZestLoopTokenStringSet getConvertedSet() throws ZestClientFailException {
    if (this.convertedSet == null) {
        if (loop == null) {
            // Not yet initialized
            return null;
        }
        ZestLoopTokenStringSet set = new ZestLoopTokenStringSet();

        WebDriver wd = this.loop.getRuntime().getWebDriver(getWindowHandle());

        List<WebElement> weList;

        if ("className".equalsIgnoreCase(type)) {
            weList = wd.findElements(By.className(this.getElement()));
        } else if ("cssSelector".equalsIgnoreCase(type)) {
            weList = wd.findElements(By.cssSelector(this.getElement()));
        } else if ("id".equalsIgnoreCase(type)) {
            weList = wd.findElements(By.id(this.getElement()));
        } else if ("linkText".equalsIgnoreCase(type)) {
            weList = wd.findElements(By.linkText(this.getElement()));
        } else if ("name".equalsIgnoreCase(type)) {
            weList = wd.findElements(By.name(this.getElement()));
        } else if ("partialLinkText".equalsIgnoreCase(type)) {
            weList = wd.findElements(By.partialLinkText(this.getElement()));
        } else if ("tagName".equalsIgnoreCase(type)) {
            weList = wd.findElements(By.tagName(this.getElement()));
        } else if ("xpath".equalsIgnoreCase(type)) {
            weList = wd.findElements(By.xpath(this.getElement()));
        } else {
            throw new ZestClientFailException(this, "Unsupported type: " + type);
        }
        for (WebElement we : weList) {
            String val;

            if (this.attribute == null || this.attribute.length() == 0) {
                val = we.getText();
            } else {
                val = we.getAttribute(attribute);
            }

            if (val != null && val.length() > 0) {
                set.addToken(val);
            }
        }

        this.convertedSet = set;
    }
    return convertedSet;
}

From source file:org.mule.modules.selenium.SeleniumModule.java

License:Open Source License

/**
 * Find all elements within the current page using the given mechanism.
 * This method is affected by the 'implicit wait' times in force at the time of execution. When
 * implicitly waiting, this method will return as soon as there are more than 0 items in the
 * found collection, or will return an empty list if the timeout is reached.
 * <p/>/*from w  w w  . j  ava2s.  co m*/
 * Only one of the attributes can be used at any given time.
 * <p/>
 * {@sample.xml ../../../doc/mule-module-selenium.xml.sample selenium:find-elements}
 *
 * @param id              The value of the "id" attribute to search for
 * @param linkText        The exact text to match against
 * @param partialLinkText The text to match against
 * @param elementName            The value of the "name" attribute to search for
 * @param tagName         The element's tagName
 * @param xpathExpression The xpath to use
 * @param cssSelectorSyntax The css expression to use
 * @param className       The value of the "class" attribute to search for
 * @return A list of all {@link WebElement}s, or an empty list if nothing matches
 */
@Processor
public List<WebElement> findElements(@Optional String id, @Optional String linkText,
        @Optional String partialLinkText, @Optional String elementName, @Optional String tagName,
        @Optional String xpathExpression, @Optional String cssSelectorSyntax, @Optional String className) {

    if (id == null && linkText == null && partialLinkText == null && elementName == null && tagName == null
            && xpathExpression == null && className == null && cssSelectorSyntax == null) {
        throw new IllegalArgumentException("At least one find criteria must be specified.");
    }

    if (!onlyOne(id, linkText, partialLinkText, elementName, tagName, xpathExpression, className,
            cssSelectorSyntax)) {
        throw new IllegalArgumentException("Only one attribute can be used");
    }

    if (id != null) {
        return webDriver.findElements(By.id(id));
    } else if (linkText != null) {
        return webDriver.findElements(By.linkText(linkText));
    } else if (partialLinkText != null) {
        return webDriver.findElements(By.partialLinkText(partialLinkText));
    } else if (elementName != null) {
        return webDriver.findElements(By.name(elementName));
    } else if (tagName != null) {
        return webDriver.findElements(By.tagName(tagName));
    } else if (xpathExpression != null) {
        return webDriver.findElements(By.xpath(xpathExpression));
    } else if (cssSelectorSyntax != null) {
        return webDriver.findElements(By.cssSelector(cssSelectorSyntax));
    } else if (className != null) {
        return webDriver.findElements(By.className(className));
    }

    return null;
}

From source file:org.mule.modules.selenium.SeleniumModule.java

License:Open Source License

/**
 * Find the first {@link WebElement} using the given method.
 * This method is affected by the 'implicit wait' times in force at the time of execution.
 * The findElement(..) invocation will return a matching row, or try again repeatedly until
 * the configured timeout is reached./*from   w w  w. ja v a2s  .c o  m*/
 * <p/>
 * {@sample.xml ../../../doc/mule-module-selenium.xml.sample selenium:find-element}
 *
 * @param id              The value of the "id" attribute to search for
 * @param linkText        The exact text to match against
 * @param partialLinkText The text to match against
 * @param elementName            The value of the "name" attribute to search for
 * @param tagName         The element's tagName
 * @param xpathExpression The xpath to use
 * @param cssSelectorSyntax The css expression to use
 * @param className       The value of the "class" attribute to search for   * @return The first matching element on the current page
 * @return A singlel {@link WebElement}, or null if nothing matches
 * @throws org.openqa.selenium.NoSuchElementException
 *          If no matching elements are found
 */
@Processor
public WebElement findElement(@Optional String id, @Optional String linkText, @Optional String partialLinkText,
        @Optional String elementName, @Optional String tagName, @Optional String xpathExpression,
        @Optional String cssSelectorSyntax, @Optional String className) {

    if (id == null && linkText == null && partialLinkText == null && elementName == null && tagName == null
            && xpathExpression == null && className == null && cssSelectorSyntax == null) {
        throw new IllegalArgumentException("At least one find criteria must be specified.");
    }

    if (!onlyOne(id, linkText, partialLinkText, elementName, tagName, xpathExpression, className,
            cssSelectorSyntax)) {
        throw new IllegalArgumentException("Only one attribute can be used");
    }

    if (id != null) {
        return webDriver.findElement(By.id(id));
    } else if (linkText != null) {
        return webDriver.findElement(By.linkText(linkText));
    } else if (partialLinkText != null) {
        return webDriver.findElement(By.partialLinkText(partialLinkText));
    } else if (elementName != null) {
        return webDriver.findElement(By.name(elementName));
    } else if (tagName != null) {
        return webDriver.findElement(By.tagName(tagName));
    } else if (xpathExpression != null) {
        return webDriver.findElement(By.xpath(xpathExpression));
    } else if (cssSelectorSyntax != null) {
        return webDriver.findElement(By.cssSelector(cssSelectorSyntax));
    } else if (className != null) {
        return webDriver.findElement(By.className(className));
    }

    return null;
}

From source file:org.nuxeo.connect.tools.report.web.RootPage.java

License:Apache License

ReportRunnerPage getRunnerPage() {
    WebElement link = findElement(By.partialLinkText("report"));
    link.click();
    return getPage(ReportRunnerPage.class);
}

From source file:org.nuxeo.ecm.webengine.test.WebEngineHomePage.java

License:Open Source License

protected WebElement getModuleLink(String name) {
    return findElement(By.partialLinkText(name));
}

From source file:org.nuxeo.ecm.webengine.test.WebEngineHomePage.java

License:Open Source License

public boolean hasModule(String name) {
    return hasElement(By.partialLinkText(name));
}

From source file:org.nvonop.selenium.framework.ObjectMap.java

License:Open Source License

private By buildLocator(String locatorType, String locatorValue) {
    if ("id".equalsIgnoreCase(locatorType)) {
        return By.id(locatorValue);
    } else if ("name".equalsIgnoreCase(locatorType)) {
        return By.name(locatorValue);
    } else if (("classname".equalsIgnoreCase(locatorType)) || ("class".equalsIgnoreCase(locatorType))) {
        return By.className(locatorValue);
    } else if (("tagname".equalsIgnoreCase(locatorType)) || ("tag".equalsIgnoreCase(locatorType))) {
        return By.className(locatorValue);
    } else if (("linktext".equalsIgnoreCase(locatorType)) || ("link".equalsIgnoreCase(locatorType))) {
        return By.linkText(locatorValue);
    } else if ("partiallinktext".equalsIgnoreCase(locatorType)) {
        return By.partialLinkText(locatorValue);
    } else if (("cssselector".equalsIgnoreCase(locatorType)) || ("css".equalsIgnoreCase(locatorType))) {
        return By.cssSelector(locatorValue);
    } else if ("xpath".equalsIgnoreCase(locatorType)) {
        return By.xpath(locatorValue);
    } else {// w  w w .ja va  2  s . c om
        LOGGER.log(Level.SEVERE, MESSAGE_LOCATOR_TYPE_NOT_DEFINED + locatorType);
        return null;
    }
}

From source file:org.nvonop.selenium.framework.utilities.TestHelper.java

License:Open Source License

private By buildLocator(String locatorType, String locatorValue) {
    // Return a instance of By class based on type of locator
    if ("id".equalsIgnoreCase(locatorType)) {
        return By.id(locatorValue);
    } else if ("name".equalsIgnoreCase(locatorType)) {
        return By.name(locatorValue);
    } else if (("classname".equalsIgnoreCase(locatorType)) || ("class".equalsIgnoreCase(locatorType))) {
        return By.className(locatorValue);
    } else if (("tagname".equalsIgnoreCase(locatorType)) || ("tag".equalsIgnoreCase(locatorType))) {
        return By.className(locatorValue);
    } else if (("linktext".equalsIgnoreCase(locatorType)) || ("link".equalsIgnoreCase(locatorType))) {
        return By.linkText(locatorValue);
    } else if ("partiallinktext".equalsIgnoreCase(locatorType)) {
        return By.partialLinkText(locatorValue);
    } else if (("cssselector".equalsIgnoreCase(locatorType)) || ("css".equalsIgnoreCase(locatorType))) {
        return By.cssSelector(locatorValue);
    } else if ("xpath".equalsIgnoreCase(locatorType)) {
        return By.xpath(locatorValue);
    } else {/*from   w ww. j  av  a 2 s. c  o m*/
        LOGGER.log(Level.SEVERE, "Locator type '" + locatorType + "' not defined!!");
        return null;
    }
}