Example usage for org.openqa.selenium By xpath

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

Introduction

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

Prototype

public static By xpath(String xpathExpression) 

Source Link

Usage

From source file:com.atanas.kanchev.testframework.selenium.handlers.Finder.java

License:Apache License

/**
 * {@inheritDoc}/*  w w w .  j a  v a 2 s  .co  m*/
 */
@Override
public Finder containingText(final String text) {

    if (text == null)
        throw new CustomExceptions.Common.NullArgumentException();
    else
        ((SeleniumContext) context().getCurrentContext()).setCurrentElement(findElement(
                By.xpath(".//*/text()[contains(normalize-space(.), " + Quotes.escape(text) + ")]/parent::*")));
    return this;

}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Finder.java

License:Apache License

/**
 * {@inheritDoc}/*w w w . j a  va2 s.c om*/
 */
@Override
public Finder havingText(final String text) {

    if (text == null)
        throw new CustomExceptions.Common.NullArgumentException();
    else
        ((SeleniumContext) context().getCurrentContext()).setCurrentElement(findElement(
                By.xpath(".//*/text()[normalize-space(.) = " + Quotes.escape(text) + "]/parent::*")));
    return this;

}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Finder.java

License:Apache License

/**
 * {@inheritDoc}//from  w  w  w.java 2 s  . c  o m
 */
@Override
public Finder byScrollingByAttribute(String attribute, String value) {

    ((SeleniumContext) context().getCurrentContext())
            .setCurrentElement(findElement(By.xpath("//*[contains(@" + attribute + ", '" + value + "')]")));
    new JSExecutor().executeScript(driver, "arguments[0].scrollIntoView(true);",
            ((SeleniumContext) context().getCurrentContext()).getCurrentElement());

    return this;
}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Finder.java

License:Apache License

/**
 * {@inheritDoc}/*from   w w  w  .  j av  a  2 s  .  c  o m*/
 */
@Override
public Finder byScrollingByTag(String tag, String value) {

    ((SeleniumContext) context().getCurrentContext())
            .setCurrentElement(findElement(By.xpath("//*[contains(" + tag + ", '" + value + "')]")));
    new JSExecutor().executeScript(driver, "arguments[0].scrollIntoView(true);",
            ((SeleniumContext) context().getCurrentContext()).getCurrentElement());

    return this;
}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Finder.java

License:Apache License

/**
 * {@inheritDoc}//from w w  w  .j av  a2 s  .  c o  m
 */
@Override
public Finder byScrollingByText(String text, boolean isExactMatch) {

    if (isExactMatch)
        ((SeleniumContext) context().getCurrentContext())
                .setCurrentElement(findElement(By.xpath("//*[.=\"" + text + "\"]")));
    else
        ((SeleniumContext) context().getCurrentContext())
                .setCurrentElement(findElement(By.xpath("//*[contains(text(), \"" + text + "\")]")));

    new JSExecutor().executeScript(driver, "arguments[0].scrollIntoView(true);",
            ((SeleniumContext) context().getCurrentContext()).getCurrentElement());

    return this;
}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Finder.java

License:Apache License

/**
 * {@inheritDoc}/*from  w  w  w  .j av a 2 s . c  om*/
 */
@Override
public Finder goToRootElement() {

    try {
        ((SeleniumContext) context().getCurrentContext())
                .setCurrentElement(findElement(By.xpath("/html/body")));
    } catch (NoSuchElementException nsee) {
        logger.error("Unable to return to Root Element - Body");
    }

    return this;
}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Finder.java

License:Apache License

/**
 * {@inheritDoc}//from   w  ww .j  a v  a  2  s  . c  om
 */
@Override
public Finder goToChild() {

    // Step into child element
    ((SeleniumContext) context().getCurrentContext()).setCurrentElement(findElement(By.xpath("./*[1]")));

    return this;

}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Finder.java

License:Apache License

/**
 * {@inheritDoc}//from  w  w  w  . j  ava 2s . co m
 */
@Override
public Finder goToParent() {

    // Step up to parent element
    ((SeleniumContext) context().getCurrentContext()).setCurrentElement(findElement(By.xpath("..")));
    return this;
}

From source file:com.atlassian.jira.webtest.webdriver.tests.visualregression.TestVisualRegressionSmoke.java

@Test
public void testUserBrowser() {
    jira.goTo(UserBrowserPage.class).setUserFilterTo10Users().gotoResultPage(2);

    /*// w  w  w  . j  a v  a  2s.  co  m
     * As we just logged in with 'admin', its login info will have been updated to the current time.
     * We should ignore that info in the screenshot.
     */
    addElementsToIgnore(By.xpath(
            "//table[@id=\"user_browser_table\"]/tbody/tr[@data-user=\"admin\"]/td[@data-cell-type=\"login-details\"]"));

    // Take the screenshot and compare.
    assertUIMatches("user-browser");
}

From source file:com.atomicleopard.webelemental.Element.java

License:Open Source License

public Element parent() {
    EList<WebElement> list = new EListImpl<WebElement>();
    for (WebElement element : elements) {
        list.addAll(element.findElements(By.xpath("..")));
    }/*from   w w w .ja v  a  2 s  .co m*/
    return new Element(list);
}