Search in sources :

Example 1 with NoSuchFrameException

use of org.openqa.selenium.NoSuchFrameException in project selenide by selenide.

the class FrameByIdOrNameTest method apply_shouldIgnore_noSuchFrameException.

@Test
void apply_shouldIgnore_noSuchFrameException() {
    WebDriver webdriver = mock(WebDriver.class);
    doThrow(new NoSuchFrameException("No frame element found by name or id paymentFrame")).when(webdriver).findElement(any());
    assertThat(new FrameByIdOrName("paymentFrame").apply(webdriver)).isNull();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) NoSuchFrameException(org.openqa.selenium.NoSuchFrameException) Test(org.junit.jupiter.api.Test)

Example 2 with NoSuchFrameException

use of org.openqa.selenium.NoSuchFrameException in project sentinel by dougnoel.

the class Element method findElementInIFrame.

/**
 * Searches recursively through any iFrames on the page for the element. Returns
 * null if the element is not found, or if there are no iFrames on the page. This
 * method traverses through iFrames but returns to the default root context upon
 * returning.
 *
 * @return WebElement the element if it is found, otherwise null
 */
protected WebElement findElementInIFrame() {
    if (PageManager.getPage().hasIFrames()) {
        WebElement element = null;
        List<WebElement> iframes = PageManager.getPage().getIFrames();
        try {
            for (WebElement iframe : iframes) {
                driver().switchTo().frame(iframe);
                element = findElementInCurrentFrameForDuration(Time.loopInterval());
                if (element != null) {
                    return element;
                }
                element = findElementInIFrame();
                if (element != null)
                    return element;
                driver().switchTo().parentFrame();
            }
        } catch (StaleElementReferenceException | NoSuchFrameException e) {
            var errorMessage = SentinelStringUtils.format("Error when searching for {} element named \"{}\" while attempting to search through iFrames. Looping again. Error: {}", elementType, getName(), e);
            log.trace(errorMessage);
            return null;
        }
    }
    return null;
}
Also used : StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) NoSuchFrameException(org.openqa.selenium.NoSuchFrameException) WebElement(org.openqa.selenium.WebElement)

Example 3 with NoSuchFrameException

use of org.openqa.selenium.NoSuchFrameException in project selenese-runner-java by vmi.

the class SelectFrame method executeImpl.

@Override
protected Result executeImpl(Context context, String... curArgs) {
    String locator = curArgs[ARG_LOCATOR];
    WebDriver driver = context.getWrappedDriver();
    WebDriverElementFinder elementFinder = context.getElementFinder();
    // ns
    long timeout = context.getTimeout() * MILLI_TO_NANO;
    long start = System.nanoTime();
    while (true) {
        try {
            elementFinder.selectFrame(driver, locator);
            return SUCCESS;
        } catch (NoSuchFrameException e) {
            if (System.nanoTime() - start > timeout) {
                log.warn("Timed out select frame: {}", locator);
                throw e;
            }
        }
        Wait.sleep(RETRY_INTERVAL);
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) NoSuchFrameException(org.openqa.selenium.NoSuchFrameException) WebDriverElementFinder(jp.vmi.selenium.selenese.locator.WebDriverElementFinder)

Example 4 with NoSuchFrameException

use of org.openqa.selenium.NoSuchFrameException in project seleniumRobot by bhecquet.

the class HtmlElement method enterFrame.

/**
 * Method for going into the right frame before doing anything else this method
 * should be called each time we need to get an element Therefore, it's used
 * inside findElement() method
 */
private void enterFrame() {
    List<FrameElement> frameTree = new ArrayList<>();
    FrameElement frame = getFrameElement();
    while (frame != null) {
        frameTree.add(0, frame);
        frame = frame.getFrameElement();
    }
    for (FrameElement frameEl : frameTree) {
        Integer idx = frameEl.getElementIndex() == null ? 0 : frameEl.getElementIndex();
        WebElement frameWebElement;
        try {
            frameWebElement = getDriver().findElements(frameEl.getBy()).get(idx);
        } catch (IndexOutOfBoundsException e) {
            throw new NoSuchFrameException(String.format("Frame %s with index %d has not been found", frameEl, idx));
        }
        ((CustomEventFiringWebDriver) getDriver()).scrollToElement(frameWebElement, -20);
        getDriver().switchTo().frame(frameWebElement);
    }
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) ArrayList(java.util.ArrayList) NoSuchFrameException(org.openqa.selenium.NoSuchFrameException) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement)

Example 5 with NoSuchFrameException

use of org.openqa.selenium.NoSuchFrameException in project seleniumRobot by bhecquet.

the class SeleniumNativeActions method recordFrameSwitch.

/**
 * Method interceptFindHtmlElement creates an HtmlElement from findElement, but does not handle frames.
 * Here, we record all switchTo().frame(WebElement) call to create a FrameElement chain
 * @param joinPoint
 * @return
 * @throws Throwable
 */
@Around(// caller is a PageObject
"this(com.seleniumtests.uipage.PageObject) && " + "(call(public * org.openqa.selenium.support.ui.ExpectedConditions.frameToBeAvailableAndSwitchToIt (..))" + ")")
public Object recordFrameSwitch(ProceedingJoinPoint joinPoint) throws Throwable {
    if (Boolean.TRUE.equals(doOverride())) {
        Object frameArg = joinPoint.getArgs()[0];
        FrameElement frameEl = getFrameElement(frameArg);
        if (frameEl == null) {
            return joinPoint.proceed(joinPoint.getArgs());
        }
        if (getCurrentFrame() == null) {
            setCurrentFrame(frameEl);
        } else {
            frameEl.setFrameElement(getCurrentFrame());
            setCurrentFrame(frameEl);
        }
        return new ExpectedCondition<WebDriver>() {

            @Override
            public WebDriver apply(WebDriver driver) {
                try {
                    return driver;
                } catch (NoSuchFrameException e) {
                    return null;
                }
            }

            @Override
            public String toString() {
                return "frame to be available: " + frameArg;
            }
        };
    } else {
        return joinPoint.proceed(joinPoint.getArgs());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) NoSuchFrameException(org.openqa.selenium.NoSuchFrameException) FrameElement(com.seleniumtests.uipage.htmlelements.FrameElement) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) Around(org.aspectj.lang.annotation.Around)

Aggregations

NoSuchFrameException (org.openqa.selenium.NoSuchFrameException)6 WebDriver (org.openqa.selenium.WebDriver)4 WebDriverElementFinder (jp.vmi.selenium.selenese.locator.WebDriverElementFinder)2 WebElement (org.openqa.selenium.WebElement)2 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)1 FrameElement (com.seleniumtests.uipage.htmlelements.FrameElement)1 ArrayList (java.util.ArrayList)1 Around (org.aspectj.lang.annotation.Around)1 Test (org.junit.jupiter.api.Test)1 StaleElementReferenceException (org.openqa.selenium.StaleElementReferenceException)1 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)1 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)1