Search in sources :

Example 66 with NoSuchElementException

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

the class AndroidUtils method scroll.

/**
 * Scrolls into view in a container specified by it's instance (index)
 * @param scrollToEle - has to be id, text, contentDesc or className
 * @param scrollableContainer - ExtendedWebElement type
 * @param containerSelectorType - has to be id, text, textContains, textStartsWith, Description, DescriptionContains
 *                             or className
 * @param containerInstance - has to an instance number of desired container
 * @param eleSelectorType -  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, 1,
 *                          AndroidUtils.SelectorType.TEXT);
 */
public static ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer, SelectorType containerSelectorType, int containerInstance, SelectorType eleSelectorType) {
    ExtendedWebElement el = null;
    long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
    for (int i = 0; i < SCROLL_MAX_SEARCH_SWIPES; i++) {
        try {
            WebElement ele = DriverPool.getDriver().findElement(MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ".instance(" + containerInstance + "))" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")" + ".scrollIntoView(" + getScrollToElementSelector(scrollToEle, eleSelectorType) + ")"));
            if (ele.isDisplayed()) {
                LOGGER.info("Element found!!!");
                el = new ExtendedWebElement(ele, scrollToEle, DriverPool.getDriver());
                break;
            }
        } catch (NoSuchElementException noSuchElement) {
            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) + ".instance(" + containerInstance + ")).scrollForward()");
            LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");
        }
    }
    return el;
}
Also used : ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) WebElement(org.openqa.selenium.WebElement) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 67 with NoSuchElementException

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

the class AndroidUtils 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 static ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer, SelectorType containerSelectorType, SelectorType eleSelectorType) {
    ExtendedWebElement el = null;
    long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
    for (int i = 0; i < SCROLL_MAX_SEARCH_SWIPES; i++) {
        try {
            WebElement ele = DriverPool.getDriver().findElement(MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ")" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")" + ".scrollIntoView(" + getScrollToElementSelector(scrollToEle, eleSelectorType) + ")"));
            if (ele.isDisplayed()) {
                LOGGER.info("Element found!!!");
                el = new ExtendedWebElement(ele, scrollToEle, DriverPool.getDriver());
                break;
            }
        } catch (NoSuchElementException noSuchElement) {
            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()");
            LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");
        }
    }
    return el;
}
Also used : ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) WebElement(org.openqa.selenium.WebElement) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 68 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project devonfw-testing by devonfw.

the class NewChromeDriver method findElement.

/**
 * @deprecated As of release 1.0.0, replaced by {@link #findElementDynamic(By)()}
 */
@Deprecated
@Override
public WebElement findElement(By by) throws BFElementNotFoundException {
    BaseTest.getAnalytics().sendMethodEvent(BasePage.analitycsCategoryName);
    WebElement elementFromDriver = null;
    try {
        elementFromDriver = super.findElement(by);
    } catch (NoSuchElementException e) {
        throw new BFElementNotFoundException(by);
    }
    return new NewRemoteWebElement(elementFromDriver);
}
Also used : BFElementNotFoundException(com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 69 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project devonfw-testing by devonfw.

the class NewInternetExplorerDriver method findElement.

/**
 * @deprecated As of release 1.0.0, replaced by {@link #findElementDynamic(By)()}
 */
@Deprecated
@Override
public WebElement findElement(By by) throws BFElementNotFoundException {
    BasePage.getAnalytics().sendMethodEvent(BasePage.analitycsCategoryName);
    WebElement elementFromDriver = null;
    try {
        elementFromDriver = super.findElement(by);
    } catch (NoSuchElementException e) {
        throw new BFElementNotFoundException(by);
    }
    return new NewRemoteWebElement(elementFromDriver);
}
Also used : BFElementNotFoundException(com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 70 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project devonfw-testing by devonfw.

the class DriverExtention method waitForElement.

public WebElement waitForElement(final By by) throws BFElementNotFoundException {
    BasePage.getAnalytics().sendMethodEvent(BasePage.analitycsCategoryName);
    long startTime = System.currentTimeMillis();
    WebElement element = null;
    FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver);
    wait.pollingEvery(250, TimeUnit.MILLISECONDS);
    wait.withTimeout(2, TimeUnit.MINUTES);
    try {
        element = webDriverWait().until(new Function<WebDriver, WebElement>() {

            @Override
            public WebElement apply(WebDriver driver) {
                return driver.findElement(by);
            }
        });
    } catch (TimeoutException | NoSuchElementException e) {
        boolean isTimeout = true;
        throw new BFElementNotFoundException(by, isTimeout, BasePage.EXPLICITYWAITTIMER);
    }
    BFLogger.logTime(startTime, "waitForElement()", by.toString());
    return element;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Function(java.util.function.Function) FluentWait(org.openqa.selenium.support.ui.FluentWait) BFElementNotFoundException(com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TimeoutException(org.openqa.selenium.TimeoutException)

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