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) 

Source Link

Usage

From source file:br.eti.kinoshita.selenium.util.Utils.java

License:Open Source License

/**
 * Wait for assync content in a determined period
 * /* w ww . ja v  a 2  s.  c  om*/
 * @param driver Selenium web driver.
 * @param by Selenium By expression.
 * @param timeout Selenium time out.
 * @return a WebElement asynchronously loaded.
 * @throws NoSuchElementException
 */
public static WebElement waitForAssyncContent(WebDriver driver, By by, Long timeout)
        throws NoSuchElementException {
    long end = System.currentTimeMillis() + (timeout);
    WebElement renderedWebElement = null;

    while (System.currentTimeMillis() < end) {
        try {
            renderedWebElement = driver.findElement(by);
        } catch (NoSuchElementException nsee) {
            LOGGER.debug(nsee.getMessage(), nsee);
        }

        if (renderedWebElement != null && renderedWebElement.isEnabled() && renderedWebElement.isDisplayed()) {
            return renderedWebElement;
        }

        try {
            Thread.sleep(1000);
        } catch (InterruptedException ie) {
            LOGGER.debug(ie.getMessage(), ie);
        }
    }

    if (renderedWebElement == null) {
        throw new NoSuchElementException("Could not locate assync content");
    }

    try {
        if (renderedWebElement.isDisplayed()) {
            throw new NoSuchElementException("Element is not being displayed");
        }
    } catch (Throwable t) {
        LOGGER.debug(t.getMessage(), t);
    }

    return renderedWebElement;
}

From source file:cat.calidos.morfeu.webapp.ui.UICell.java

License:Apache License

public UICellData cellInfo() {

    if (!isActive()) {
        throw new NoSuchElementException("Trying the to get the info of a not active cell");

    }/*ww w. j av a  2s .  c  om*/

    return new UICellData(); // at the moment there is only one info

}

From source file:cat.calidos.morfeu.webapp.ui.UICell.java

License:Apache License

public UICellEditor edit() {

    if (!isActive()) {
        throw new NoSuchElementException("Trying the to get the editor of a not active cell");

    }/*from ww  w.  ja  v  a  2  s .  c  o  m*/
    content.pressKey("e");

    return new UICellEditor(content);

}

From source file:cat.calidos.morfeu.webapp.ui.UICellModelEntry.java

License:Apache License

public UICellData cellInfo() {

    if (!isActive()) {
        throw new NoSuchElementException("Trying the to get the info of an inactive cell model");
    }/*from ww w  .  j  a v a 2  s  .c  o  m*/

    return new UICellData(); // at the moment there is only one info :)

}

From source file:ch.admin.isb.hermes5.common.AbstractPageDriver.java

License:Apache License

public WebElement selectOptionWithName(WebElement selectOneMenu, String string) {
    for (WebElement option : allOptions(selectOneMenu)) {
        if (option.getText().startsWith(string)) {
            return option;
        }// w ww .  ja  v a 2s  . co m
    }
    throw new NoSuchElementException(string + " in " + selectOneMenu);
}

From source file:ch.admin.isb.hermes5.common.AbstractPageDriver.java

License:Apache License

public WebElement selectOptionWithValue(WebElement selectOneMenu, String value) {
    for (WebElement option : allOptions(selectOneMenu)) {
        if (option.getAttribute("value").equals(value)) {
            return option;
        }/* ww w  . j  av  a2s .  c o m*/
    }
    throw new NoSuchElementException(value + " in " + selectOneMenu + "\n" + driver.getPageSource());
}

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

License:Apache License

private List<WebElement> findElements(By locator) {
    logger.debug("Locating elements using " + locator.toString());
    try {/*from   www.ja  va 2  s.  co  m*/
        List<WebElement> e = driver.findElements(locator);
        int numberOfElementsFound = e.size();
        if (numberOfElementsFound == 0)
            throw new NoSuchElementException("Elements found: " + numberOfElementsFound);
        logger.debug("Elements found: " + numberOfElementsFound);
        return e;
    } catch (NoSuchElementException nsee) {
        throw new NoSuchElementException("Unable to locate any elements using " + locator.toString(), nsee);
    }
}

From source file:com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.Select.java

License:Apache License

/**
 * Selects given options of select component.
 *
 * @param value String value of comma delimited field names which will be selected.
 *//* w ww. ja  v  a  2s.  c  o  m*/
@Override
public void setValue(Object value) {
    selectField.click();
    List<WebElement> options = selectField.findElements(By.cssSelector(SELECT_OPTIONS_CSS));
    options.stream().filter(o -> value.toString().equals(o.getText())).findFirst().orElseThrow(
            () -> new NoSuchElementException(String.format("Option with text %s not found", value.toString())))
            .click();
}

From source file:com.denimgroup.threadfix.selenium.pages.ApplicationDetailPage.java

License:Mozilla Public License

public void waitForScanUpload(int timer) {
    if (timer == 20) {
        throw new NoSuchElementException(
                "Unable to locate element: {\"method\":\"id\",\"selector\":\"scanTabLink\"}");
    }/*w  w w . ja  v a 2  s .  c o  m*/
    try {
        driver.findElementById("scanTabLink");
    } catch (NoSuchElementException e) {
        sleep(1000);
        waitForScanUpload(timer + 1);
    }

}

From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.pages.EnvironmentCreationPage.java

License:Apache License

private void selectReleaseName(String releaseName) {
    Select releaseNames = new Select(applicationReleaseInput);
    try {//from  w  w  w .ja v  a  2 s  . c  o m
        releaseNames.selectByVisibleText(releaseName);
    } catch (org.openqa.selenium.NoSuchElementException e) {
        throw new NoSuchElementException("Cannot select application release name " + releaseName
                + ". application release names available for selection are : " + getOptions(releaseNames));
    }
}