Search in sources :

Example 81 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project carina by zebrunner.

the class DriverHelper method waitUntil.

/**
 * Wait until any condition happens.
 *
 * @param condition - ExpectedCondition.
 * @param timeout - timeout.
 * @return true if condition happen.
 */
public boolean waitUntil(ExpectedCondition<?> condition, long timeout) {
    boolean result;
    long startMillis = 0;
    final WebDriver drv = getDriver();
    Wait<WebDriver> wait = new WebDriverWait(drv, timeout, RETRY_TIME).ignoring(WebDriverException.class).ignoring(NoSuchSessionException.class);
    try {
        startMillis = System.currentTimeMillis();
        wait.until(condition);
        result = true;
        LOGGER.debug("waitUntil: finished true...");
    } catch (NoSuchElementException | TimeoutException e) {
        // don't write exception even in debug mode
        LOGGER.debug("waitUntil: NoSuchElementException | TimeoutException e..." + condition.toString());
        result = false;
    } catch (Exception e) {
        LOGGER.error("waitUntil: " + condition.toString(), e);
        result = false;
    } finally {
        long timePassed = System.currentTimeMillis() - startMillis;
        // timePassed is time in ms timeout in sec so we have to adjust
        if (timePassed > 2 * timeout * 1000) {
            LOGGER.error("Your retry_interval is too low: " + RETRY_TIME + " ms! Increase it or upgrade your hardware");
        }
    }
    return result;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TimeoutException(org.openqa.selenium.TimeoutException) JavascriptException(org.openqa.selenium.JavascriptException) NoSuchSessionException(org.openqa.selenium.NoSuchSessionException) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException) WebDriverException(org.openqa.selenium.WebDriverException) UnhandledAlertException(org.openqa.selenium.UnhandledAlertException) JsonException(org.openqa.selenium.json.JsonException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) ExecutionException(java.util.concurrent.ExecutionException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) NoSuchWindowException(org.openqa.selenium.NoSuchWindowException) WebDriverException(org.openqa.selenium.WebDriverException) TimeoutException(org.openqa.selenium.TimeoutException) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException)

Example 82 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project carina by zebrunner.

the class IAndroidUtils method scroll.

/**
 * Scrolls into view in specified container
 *
 * @param scrollToEle
 *            - has to be id, text, contentDesc or className
 * @param scrollableContainer
 *            - ExtendedWebElement type
 * @param containerSelectorType
 *            - container Selector type: has to be id, text, textContains,
 *            textStartsWith, Description, DescriptionContains or className
 * @param eleSelectorType
 *            - scrollToEle Selector type: has to be id, text, textContains,
 *            textStartsWith, Description, DescriptionContains or className
 * @return ExtendedWebElement
 *         <p>
 *         example of usage: ExtendedWebElement res =
 *         AndroidUtils.scroll("News", newsListContainer,
 *         AndroidUtils.SelectorType.CLASS_NAME,
 *         AndroidUtils.SelectorType.TEXT);
 */
public default ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer, SelectorType containerSelectorType, SelectorType eleSelectorType) {
    ExtendedWebElement extendedWebElement = null;
    long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
    // TODO: support multi threaded WebDriver's removing DriverPool usage
    WebDriver drv = castDriver();
    // workaorund for appium issue: https://github.com/appium/appium/issues/10159
    if (scrollToEle.contains(",")) {
        scrollToEle = StringUtils.join(StringUtils.split(scrollToEle, ","), ",", 0, 2);
        if (eleSelectorType.equals(SelectorType.TEXT)) {
            eleSelectorType = SelectorType.TEXT_CONTAINS;
        }
    }
    for (int i = 0; i < SCROLL_MAX_SEARCH_SWIPES; i++) {
        try {
            By scrollBy = MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ")" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")" + ".scrollIntoView(" + getScrollToElementSelector(scrollToEle, eleSelectorType) + ")");
            WebElement ele = drv.findElement(scrollBy);
            if (ele.isDisplayed()) {
                UTILS_LOGGER.info("Element found!!!");
                extendedWebElement = new ExtendedWebElement(scrollBy, scrollToEle, drv);
                break;
            }
        } catch (NoSuchElementException noSuchElement) {
            UTILS_LOGGER.error(String.format("Element %s:%s was NOT found.", eleSelectorType, scrollToEle), noSuchElement);
        }
        for (int j = 0; j < i; j++) {
            checkTimeout(startTime);
            MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ").scrollForward()");
            UTILS_LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");
        }
    }
    return extendedWebElement;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) MobileBy(io.appium.java_client.MobileBy) By(org.openqa.selenium.By) WebElement(org.openqa.selenium.WebElement) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 83 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project testsigma by testsigmahq.

the class SelectOptionByValueAction method execute.

@Override
protected void execute() throws Exception {
    findElement();
    Select selectElement = new Select(getElement());
    try {
        selectElement.selectByValue(getTestData());
        setSuccessMessage(SUCCESS_MESSAGE);
    } catch (NoSuchElementException e) {
        throw new AutomatorException(String.format(FAILURE_MESSAGE, getTestData(), getFindByType(), getLocatorValue(), getTestData()));
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) Select(org.openqa.selenium.support.ui.Select) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 84 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project testsigma by testsigmahq.

the class SelectOptionByVisibleTextAction method execute.

@Override
protected void execute() throws Exception {
    try {
        findElement();
        Select selectElement = new Select(getElement());
        selectElement.selectByVisibleText(getTestData());
        setSuccessMessage(SUCCESS_MESSAGE);
    } catch (NoSuchElementException e) {
        throw new AutomatorException(String.format(FAILURE_MESSAGE, getTestData(), getFindByType(), getLocatorValue(), getTestData()));
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) Select(org.openqa.selenium.support.ui.Select) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 85 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project healenium-example-maven by healenium.

the class MarkupPage method selectAllCheckboxes.

public int selectAllCheckboxes() {
    List<WebElement> checkboxes = driver.findElements(checkboxAccount);
    if (checkboxes.size() == 0)
        throw new NoSuchElementException("No checkboxes found");
    checkboxes.forEach(c -> c.click());
    return checkboxes.size();
}
Also used : WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Aggregations

NoSuchElementException (org.openqa.selenium.NoSuchElementException)388 WebElement (org.openqa.selenium.WebElement)210 Test (org.junit.Test)61 TimeoutException (org.openqa.selenium.TimeoutException)52 Test (org.testng.annotations.Test)50 WebDriverException (org.openqa.selenium.WebDriverException)38 MessageEvent (org.cerberus.engine.entity.MessageEvent)34 WebDriver (org.openqa.selenium.WebDriver)30 Test (org.junit.jupiter.api.Test)29 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)29 MockitoTest (com.seleniumtests.MockitoTest)23 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)23 Select (org.openqa.selenium.support.ui.Select)22 By (org.openqa.selenium.By)20 AnswerItem (org.cerberus.util.answer.AnswerItem)18 WebElementLocator (de.learnlib.alex.data.entities.WebElementLocator)16 StaleElementReferenceException (org.openqa.selenium.StaleElementReferenceException)14 Actions (org.openqa.selenium.interactions.Actions)14 ArrayList (java.util.ArrayList)13 CerberusEventException (org.cerberus.exception.CerberusEventException)11