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:com.seleniumtests.uipage.htmlelements.HtmlElement.java

License:Apache License

/**
 * Find elements inside this element//  w  w  w  .  j a  v  a 2s.  c  o  m
 * @param by
 * @return   List of HtmlElement's based on real WebElement
 */
@ReplayOnError
public List<WebElement> findHtmlElements(By by) {

    // find the root element
    findElement(false, false);
    List<WebElement> htmlElements = new ArrayList<>();
    List<WebElement> elements = element.findElements(by);

    // throw exception so that behavior is the same as with 'findElements()' call which retries search
    if (elements.isEmpty()) {
        throw new NoSuchElementException("No elements found for " + by.toString());
    }

    for (int i = 0; i < elements.size(); i++) {
        htmlElements.add(new HtmlElement("", by, frameElement, parent, i));
    }
    return htmlElements;
}

From source file:com.softwareonpurpose.uinavigator.UiHost.java

License:Apache License

/**
 * @param locator A Selenium.By WebElement locator
 * @return WebElement within the current web page
 *///from ww  w .j a  va2  s  . c om
WebElement findUiElement(By locator) {
    List<WebElement> elements = findUiElements(locator);
    if (elements.size() > 0) {
        return elements.get(0);
    } else {
        getLogger().warn(
                String.format("WARNING: Unable to find any element using locator '%s'", locator.toString()));
    }
    return null;
}

From source file:com.softwareonpurpose.uinavigator.UiHost.java

License:Apache License

/**
 * @param locator A Selenium.By WebElement locator
 * @return A List of WebElements within the current web page
 *///from   w w w.jav  a 2  s.com
List<WebElement> findUiElements(By locator) {
    List<WebElement> elements;
    try {
        elements = getDriver().findElements(locator);
    } catch (WebDriverException e) {
        getLogger().warn(
                String.format("WARNING: Unable to find any element using locator '%s'", locator.toString()));
        return null;
    }
    return elements;
}

From source file:com.softwareonpurpose.uinavigator.UiHost.java

License:Apache License

/**
 * @param locator A Selenium.By WebElement
 * @return boolean Indicates whether the WebElement described by the By locator was visible within a defined timeout period
 *///from   w w w.  j a va 2s . c om
boolean waitUntilVisible(By locator) {
    try {
        new WebDriverWait(getDriver(), getConfig().timeout)
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
    } catch (WebDriverException e) {
        getLogger().warn(String.format("WARNING: UiElement '%s' failed to be displayed within %d seconds",
                locator.toString(), getConfig().timeout));
        return false;
    }
    return true;
}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

License:Apache License

/**
 * internal method which actually checks whether the given element is
 * exists./*w ww. j  a v a2s . c  om*/
 * 
 * @param searchPath
 *            the search path
 * @return the web element
 * @throws Exception
 *             the exception
 */
private WebElement checkElementPresence(final String searchPath) throws Exception {
    WebDriver driver = getDriver();
    WebElement webElement = null;
    String locator = searchPath;
    final Logger log = getLog();
    int count = getRetryCount();
    setCommandStartTime(getCurrentTime());
    final By searchBy = getLocatorType(locator);
    final Long retryMillis = 1000L;

    try {

        Function<WebDriver, WebElement> findElementFunction = new FindElementFunction<WebDriver, WebElement>(
                searchBy);

        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout((count * retryMillis), TimeUnit.MILLISECONDS)
                .pollingEvery(retryInterval, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class)
                .ignoring(WebDriverException.class);

        webElement = wait.until(findElementFunction);

    } catch (Exception e) {
        log.error("Element [ " + searchPath + " ] Not Found", e);
    }

    if (webElement != null) {
        try {
            log.info("Element [ " + searchBy.toString() + " ] Found");
            JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
            jsExecutor.executeScript("arguments[0].scrollIntoView(false);", webElement);
        } catch (Exception ex) {
            log.error("Exception occured while scrolling to the element.", ex);
        }
    } else {
        throw new Exception("Element " + searchPath);
    }

    return webElement;
}

From source file:daveayan.gherkinsalad.components.core.BaseBrowserElement.java

License:Open Source License

private Elements convertToElements(List<WebElement> _webElements, By locator) {
    Elements elements = new Elements();
    if (_webElements != null) {
        for (WebElement _we : _webElements) {
            elements.add(Element.newInstance(_we, locator.toString(), locator));
        }// w  w  w .  ja va  2 s.c  om
    }
    return elements;
}

From source file:de.codecentric.zucchini.web.util.WebAssert.java

License:Apache License

/**
 * Tries to find a specific element and fails if the element could not be found.
 *
 * @param webDriver The web driver.//ww w .  j  a v  a 2  s.c  om
 * @param element   The element.
 * @return The found element.
 */
public static WebElement findElementOrFail(WebDriver webDriver, By element) {
    try {
        return webDriver.findElement(element);
    } catch (NoSuchElementException e) {
        fail(String.format("Element %s should exist but it does not.", element.toString()), e);
    }
    /**
     * Never reached since {@link de.codecentric.zucchini.bdd.util.Assert#fail(String)} fail()} throws
     * {@link java.lang.AssertionError}.
     */
    return null;
}

From source file:de.knowwe.uitest.DiaFluxUITest.java

License:Open Source License

private void addNode(int xOffset, int yOffset, By prototypeSelector, By textSelector, String... text)
        throws InterruptedException {
    WebElement start = getDriver().findElement(prototypeSelector);
    new Actions(getDriver()).dragAndDropBy(start, xOffset, yOffset).perform();
    Thread.sleep(200);/*from   ww  w . j  a  v a2  s  .  com*/
    if (text.length > 0) {
        String selector = prototypeSelector.toString();
        if (selector.contains("start") || selector.contains("snapshot") || selector.contains("exit")) { // for decision nodes, editor opens automatically
            List<WebElement> nodes = getDriver().findElements(By.cssSelector(".Flowchart > .Node"));
            WebElement newNode = nodes.get(nodes.size() - 1);
            new Actions(getDriver()).doubleClick(newNode).perform();
        }
        setNodeAttributes(textSelector, text);
    }

}

From source file:edu.samplu.common.WebDriverITBase.java

License:Educational Community License

/**
 * //from w  ww. j  av  a  2s .c  om
 *
 * @param by The locating mechanism of the element
 * @param text The text to type
*/
protected void waitAndType(By by, String text) throws InterruptedException {
    waitFor(by, "");
    try {
        (driver.findElement(by)).sendKeys(text);
    } catch (Exception e) {
        fail(e.getMessage() + " " + by.toString() + " " + text);
        e.printStackTrace();
    }
}

From source file:edu.samplu.common.WebDriverITBase.java

License:Educational Community License

/**
 * /*from w ww  .j a v  a 2s.  c  om*/
 *
 * @param by The locating mechanism of the element
 * @param text The text to type
 * @param message User defined message to display
*/
protected void waitAndType(By by, String text, String message) throws InterruptedException {
    waitFor(by, "");
    try {
        (driver.findElement(by)).sendKeys(text);
    } catch (Exception e) {
        fail(e.getMessage() + " " + by.toString() + " " + text + "  " + message);
        e.printStackTrace();
    }
}