Example usage for org.openqa.selenium NoSuchElementException NoSuchElementException

List of usage examples for org.openqa.selenium NoSuchElementException NoSuchElementException

Introduction

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

Prototype

public NoSuchElementException(String reason, Throwable cause) 

Source Link

Usage

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

License:Apache License

private WebElement findElement(By locator) {
    logger.debug("Locating element using " + locator.toString());
    try {/* ww w.  j av  a 2  s. c o m*/
        return driver.findElement(locator);
    } catch (NoSuchElementException nsee) {
        throw new NoSuchElementException("Unable to locate element using " + locator.toString(), nsee);
    }
}

From source file:com.cognifide.qa.bb.aem.ui.parsys.AemInsertWindow.java

License:Apache License

private void chooseComponent(String componentGroup, String componentName, WebElement tab) {
    try {//from   ww  w . jav  a2s .co m
        tab.findElement(By.xpath(String.format("./..//button[text()=%s]", XpathUtils.quote(componentName))))
                .click();
    } catch (NoSuchElementException e) {
        throw new NoSuchElementException("No such component " + componentName + " in group: " + componentGroup,
                e);
    }
}

From source file:com.cognifide.qa.bb.aem.ui.parsys.AemInsertWindow.java

License:Apache License

private WebElement chooseTab(String componentGroup) {
    try {//  ww w  .  j a  v  a 2 s.  c om
        WebElement tab = currentScope.findElement(By.xpath(
                String.format(".//*[contains(@class,'x-panel-header')][.//span[normalize-space(text())=%s]]",
                        XpathUtils.quote(componentGroup))));
        if (TAB_FOLDED
                .equals(tab.findElement(By.cssSelector(".x-tool-toggle")).getCssValue("background-position"))) {
            tab.click();
        }
        return tab;
    } catch (NoSuchElementException e) {
        throw new NoSuchElementException("No such tab: " + componentGroup, e);
    }
}

From source file:com.mengge.pagefactory.AppiumElementLocator.java

License:Apache License

/**
 * Find the element.//from   ww w  . j a v a  2  s .co m
 */
public WebElement findElement() {
    if (cachedElement != null && shouldCache) {
        return cachedElement;
    }
    List<WebElement> result = waitFor();
    if (result.size() == 0) {
        String message = "Can't locate an element by this strategy: " + by.toString();
        if (waitingFunction.foundStaleElementReferenceException != null) {
            throw new NoSuchElementException(message, waitingFunction.foundStaleElementReferenceException);
        }
        throw new NoSuchElementException(message);
    }
    if (shouldCache) {
        cachedElement = result.get(0);
    }
    return result.get(0);
}

From source file:com.oracle.pgbu.common.pagefactory.AjaxElementLocator.java

License:Apache License

/**
 * {@inheritDoc}// ww  w. j  ava2  s  .  co m
 * 
 * Will poll the interface on a regular basis until the element is present.
 */
@Override
public WebElement findElement() {
    timeOutInSeconds = ApplicationProperties.getInstance().getPageFactoryCompLoadTime();
    SlowLoadingElement loadingElement = new SlowLoadingElement(clock, timeOutInSeconds);
    try {
        return loadingElement.get().getElement();
    } catch (NoSuchElementError e) {
        throw new NoSuchElementException(
                String.format("Timed out after %d seconds. %s", timeOutInSeconds, e.getMessage()),
                e.getCause());
    }
}

From source file:com.partnet.automation.HtmlView.java

License:Apache License

/**
 * Waits for an element to appear on the page before returning. Example:
 * WebElement waitElement =// w  ww . j  a v a  2  s  .com
 * fluentWait(By.cssSelector(div[class='someClass']));
 * 
 * @param locator locator of the element to find
 * @return Web element of found element
 */
protected WebElement waitForElementToAppear(final By locator) {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(webDriver).withTimeout(30, TimeUnit.SECONDS)
            .pollingEvery(5, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

    WebElement element = null;
    try {
        element = wait.until(new Function<WebDriver, WebElement>() {

            @Override
            public WebElement apply(WebDriver driver) {
                return driver.findElement(locator);
            }
        });
    } catch (TimeoutException e) {
        try {
            // I want the error message on what element was not found
            webDriver.findElement(locator);
        } catch (NoSuchElementException renamedErrorOutput) {
            // print that error message
            renamedErrorOutput.addSuppressed(e);
            // throw new
            // NoSuchElementException("Timeout reached when waiting for element to be found!"
            // + e.getMessage(), correctErrorOutput);
            throw renamedErrorOutput;
        }
        e.addSuppressed(e);
        throw new NoSuchElementException("Timeout reached when searching for element!", e);
    }

    return element;
}

From source file:com.vaadin.addon.spreadsheet.elements.SpreadsheetElement.java

License:Open Source License

/**
 * Fetches the context menu for the spreadsheet
 *
 * @return {@link com.vaadin.addon.spreadsheet.elements.SpreadsheetElement.ContextMenuElement}
 * @throws java.util.NoSuchElementException if the menu isn't open
 *//*w  ww .ja v  a2s  .  c om*/
public ContextMenuElement getContextMenu() {
    try {
        WebElement cm = getDriver().findElement(By.className("v-contextmenu"));
        return wrapElement(cm, getCommandExecutor()).wrap(ContextMenuElement.class);
    } catch (WebDriverException e) {
        throw new NoSuchElementException("Context menu not found", e);
    }
}

From source file:com.vaadin.testbench.TestBenchDriverProxy.java

/**
 * Finds an element by a Vaadin selector string.
 *
 * @param selector//from  www. j  a va2  s.co m
 *            TestBench4 style Vaadin selector.
 * @param context
 *            a suitable search context - either a
 *            {@link TestBenchDriverProxy} or a {@link TestBenchElement}
 *            instance.
 * @return the first element identified by the selector
 */
protected static WebElement findElementByVaadinSelector(String selector, SearchContext context) {
    // This is needed for 7.1 and earlier Vaadin versions.
    List<WebElement> elements = executeSearch(selector, context, "getElementByPath");

    if (elements.isEmpty()) {
        final String errorString = "Vaadin could not find elements with the selector " + selector;
        throw new NoSuchElementException(errorString,
                new Exception("Client could not identify elements with the provided selector"));
    }

    return elements.get(0);
}

From source file:com.vaadin.testbench.TestBenchDriverProxy.java

private static List<WebElement> executeSearch(String selector, SearchContext context, String jsFunction) {
    final String errorString = "Vaadin could not find elements with the selector " + selector;

    // Construct elementSelectionString script fragment based on type of
    // search context
    String elementSelectionString = "var element = clients[client]." + jsFunction;
    if (context instanceof WebDriver) {
        elementSelectionString += "(arguments[0]);";
    } else {//w ww .  j av a 2s .co  m
        elementSelectionString += "StartingAt(arguments[0], arguments[1]);";
    }

    String findByVaadinScript = "var clients = window.vaadin.clients;" + "for (client in clients) {"
            + elementSelectionString + "  if (element) {" + " return element;" + "  }" + "}" + "return null;";

    WebDriver driver = ((HasDriver) context).getDriver();

    JavascriptExecutor jse = (JavascriptExecutor) driver;
    List<WebElement> elements = new ArrayList<WebElement>();

    if (selector.contains("::")) {
        // We've been given specifications to access a specific client on
        // the page; the client ApplicationConnection is managed by the
        // JavaScript running on the page, so we use the driver's
        // JavaScriptExecutor to query further...
        String client = selector.substring(0, selector.indexOf("::"));
        String path = selector.substring(selector.indexOf("::") + 2);
        try {
            Object output = jse.executeScript(
                    "return window.vaadin.clients." + client + "." + jsFunction + "(\"" + path + "\");");
            elements.addAll(extractWebElements(output));
        } catch (Exception e) {
            throw new NoSuchElementException(errorString, e);
        }
    } else {
        try {
            if (context instanceof WebDriver) {
                Object output = jse.executeScript(findByVaadinScript, selector);
                elements.addAll(extractWebElements(output));
            } else {
                Object output = jse.executeScript(findByVaadinScript, selector, context);
                elements.addAll(extractWebElements(output));
            }
        } catch (Exception e) {
            throw new NoSuchElementException(errorString, e);
        }
    }

    return elements;
}

From source file:org.alfresco.po.share.cmm.admin.CreateNewModelPopUp.java

License:Open Source License

@Override
public WebElement getDialogueHeader() {
    try {/* w w w.j a va  2 s  .  co  m*/
        return findFirstDisplayedElement(SHARE_DIALOGUE_HEADER);
    } catch (NoSuchElementException nse) {
        throw new NoSuchElementException("Unable to find the css ", nse);
    }
}