Example usage for org.openqa.selenium By toString

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

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:nz.co.testamation.core.client.SeleniumBrowserDriver.java

License:Apache License

@Override
public void selectRadioByValue(String name, Object value) {
    By by = By.cssSelector(
            String.format("input[name='%s'][value='%s']", name, StringUtil.toNotNullString(value)));
    System.out.println("clicking " + by.toString());
    waitBeforeClick(by);// w w w  .j a v a 2s .co m
}

From source file:nz.co.testamation.core.client.SeleniumBrowserDriver.java

License:Apache License

public void click(final By by) {
    System.out.println("clicking " + by.toString());
    executeAndWaitForPageLoad(new Work() {
        @Override//from  w ww. j  a  v  a  2s  .c  o  m
        public void execute() {
            waitBeforeClick(by);
        }
    });
}

From source file:org.agileware.test.web.AbstractDelegatingWebDriver.java

License:Open Source License

/**
 * @see org.openqa.selenium.WebDriver#findElement(org.openqa.selenium.By)
 *///from  w  w  w. j a  va2 s  .  c  o m
public WebElement findElement(By by) {
    try {
        return new DelegatingWebElement(delegate.findElement(by));
    } catch (NoSuchElementException nsee) {
        nsee.addInfo("Find clause", by.toString());
        throw nsee;
    }
}

From source file:org.agileware.test.web.AbstractDelegatingWebDriver.java

License:Open Source License

/**
 * @see org.openqa.selenium.WebDriver#findElements(org.openqa.selenium.By)
 *///from   w  ww  . j a  v  a 2  s .  c  o  m
public List<WebElement> findElements(By by) {
    try {
        List<WebElement> results = new ArrayList<WebElement>();
        for (WebElement webElement : delegate.findElements(by)) {
            results.add(new DelegatingWebElement(webElement));
        }
        return results;
    } catch (NoSuchElementException nsee) {
        nsee.addInfo("Find clause", by.toString());
        throw nsee;
    }
}

From source file:org.alfresco.po.PageElement.java

License:Open Source License

public WebElement findFirstDisplayedElement(By selector) {
    try {/*from  w  ww. j  a  v a  2  s.  c  om*/
        List<WebElement> elementList = findDisplayedElements(selector);
        if (elementList != null && elementList.size() > 0) {
            return elementList.get(0);
        }
    } catch (NoSuchElementException e) {
        throw new NoSuchElementException("Not able find element for give locator " + e);
    }
    throw new NoSuchElementException(
            "Not able find any displayed elemment for given locator " + selector.toString());
}

From source file:org.alfresco.po.share.SharePage.java

License:Open Source License

/**
 * <li>Click the element which passed and wait for given ElementState on the same element.</li> <li>If the Element State not changed, then render the
 * {@link SharePopup} Page, if it is rendered the return {@link SharePopup} page.</li>
 * /*from   w  w  w  . j  a  v  a2  s  .  com*/
 * @param locator By
 * @param elementState ElementState
 * @return {@link HtmlPage}
 */
protected HtmlPage submit(By locator, ElementState elementState) {
    WebElement button = findFirstDisplayedElement(locator);
    String id = button.getAttribute("id");
    button.click();
    By locatorById = By.id(id);
    RenderTime time = new RenderTime(maxPageLoadingTime);
    time.start();
    while (true) {
        try {
            switch (elementState) {
            case INVISIBLE:
                waitUntilElementDisappears(locatorById, elementWaitInSeconds);
                break;
            case DELETE_FROM_DOM:
                waitUntilElementDeletedFromDom(locatorById, elementWaitInSeconds);
                break;
            default:
                throw new UnsupportedOperationException(elementState + "is not currently supported by submit.");
            }
        } catch (TimeoutException e) {
            try {
                SharePopup errorPopup = getCurrentPage().render();
                errorPopup.render(new RenderTime(popupRendertime));
                return errorPopup;
            } catch (PageRenderTimeException | ClassCastException exception) {
                logger.info("Error Submitting the page:", exception);
                continue;
            }
        } finally {
            time.end(locatorById.toString());
        }
        break;
    }
    return getCurrentPage().render();
}

From source file:org.alfresco.po.share.SharePage.java

License:Open Source License

/**
 * Method to get element text for given locator.
 * If the element is not found, returns empty string
 * //from www.  j  a va2s  .co  m
 * @param locator By
 * @return String
 */
public String getElementText(By locator) {
    try {
        return findAndWait(locator).getText();
    } catch (NoSuchElementException nse) {
        if (logger.isTraceEnabled()) {
            logger.trace("Element not found" + locator.toString(), nse);
        }
    }
    return "";
}

From source file:org.alfresco.po.share.SharePage.java

License:Open Source License

/**
 * Find the all the elements for given locator and returns the first visible {@link WebElement}.
 * It could be used to elemanate the hidden element with same locators.
 * //w  w w  .  j ava2  s .co m
 * @param locator By
 * @return {@link WebElement}
 */
protected WebElement getVisibleElement(By locator) {
    List<WebElement> searchElements = driver.findElements(locator);
    for (WebElement webElement : searchElements) {
        if (webElement.isDisplayed()) {
            return webElement;
        }
    }
    throw new PageOperationException(
            "Not able find the visible element for given locator : " + locator.toString());
}

From source file:org.alfresco.po.share.SharePage.java

License:Open Source License

/**
 * Returns the validation message from the validation popup balloon for the web element
 * or an empty string if there is no message or the field is not validated.
 * /*w w w . ja va 2 s .  c  o m*/
 * @param locator By
 * @return The validation message
 */
public String getValidationMessage(By locator) {
    String message = "";
    try {
        message = driver.findElement(locator).getAttribute("alf-validation-msg");
    } catch (NoSuchElementException exception) {
        if (logger.isTraceEnabled()) {
            logger.trace(exception + locator.toString());
        }
    }

    return (message == null ? "" : message);
}

From source file:org.alfresco.po.share.user.TrashCanItem.java

License:Open Source License

/**
 * <li>Click the element which passed and wait for given ElementState on the same element.</li> <li>If the Element State not changed, then render the
 * {@link SharePopup} Page, if it is rendered the return {@link SharePopup} page.</li>
 * // w  w  w.  j  ava  2  s  .  c  om
 * @param locator By
 * @param elementState ElementState
 * @return {@link HtmlPage}
 */
protected HtmlPage submit(By locator, ElementState elementState) {
    try {
        WebElement button = driver.findElement(locator);
        String id = button.getAttribute("id");
        button.click();
        By locatorById = By.id(id);
        long elementWaitInSeconds = getDefaultWaitTime() / 1000;
        long popupRendertime = getDefaultWaitTime() / 1000;
        RenderTime time = new RenderTime(getDefaultWaitTime());
        time.start();
        while (true) {
            try {
                switch (elementState) {
                case INVISIBLE:
                    waitUntilElementDisappears(locatorById, elementWaitInSeconds);
                    break;
                case DELETE_FROM_DOM:
                    waitUntilElementDeletedFromDom(locatorById, elementWaitInSeconds);
                    break;
                case VISIBLE:
                    waitUntilElementPresent(By.cssSelector("div.ft>span button"), elementWaitInSeconds);
                    break;
                default:
                    throw new UnsupportedOperationException(
                            elementState + "is not currently supported by submit.");
                }
            } catch (TimeoutException e) {
                SharePopup errorPopup = getCurrentPage().render();
                try {
                    errorPopup.render(new RenderTime(popupRendertime));
                    return errorPopup;
                } catch (PageRenderTimeException exception) {
                    continue;
                }
            } finally {
                time.end();
            }
            break;
        }
        return getCurrentPage();
    } catch (NoSuchElementException te) {
    }
    throw new PageException(
            "Not able to find the Page, may be locator missing in the page : " + locator.toString());
}