Java 类org.openqa.selenium.NoSuchFrameException 实例源码

项目:webtester2-core    文件:FocusSetterTest.java   
@Test
void switchingToFrameByUnknownIndexThrowsException() {
    NoSuchFrameException exception = mock(NoSuchFrameException.class);
    when(webDriver.switchTo().frame(42)).thenThrow(exception);
    assertThrows(NoSuchFrameException.class, () -> {
        cut.onFrame(42);
    });
    verify(events).fireExceptionEvent(exception);
    verifyNoMoreInteractions(events);
}
项目:crawljax    文件:WebDriverBackedEmbeddedBrowser.java   
private void switchToFrame(String frameIdentification) throws NoSuchFrameException {
    LOGGER.debug("frame identification: " + frameIdentification);

    if (frameIdentification.contains(".")) {
        String[] frames = frameIdentification.split("\\.");

        for (String frameId : frames) {
            LOGGER.debug("switching to frame: " + frameId);
            browser.switchTo().frame(frameId);
        }

    } else {
        browser.switchTo().frame(frameIdentification);
    }

}
项目:devtools-driver    文件:RemoteWebElement.java   
public RemoteWebElement getContentDocument() throws Exception {
  JsonObject response =
      getInspectorResponse(
          "(function(arg) { var document = this.contentDocument; return document;})", false);
  RemoteObject ro = inspector.cast(response);
  if (ro == null) {
    throw new NoSuchFrameException("Cannot find the document associated with the frame.");
  } else {
    return ro.getWebElement();
  }
}
项目:devtools-driver    文件:RemoteWebElement.java   
public RemoteWebElement getContentWindow() throws Exception {
  JsonObject response =
      getInspectorResponse(
          "(function(arg) { var window = this.contentWindow; return window;})", false);
  RemoteObject ro = inspector.cast(response);
  if (ro == null) {
    throw new NoSuchFrameException("Cannot find the window associated with the frame.");
  } else {
    return ro.getWebElement();
  }
}
项目:devtools-driver    文件:SetFrameHandler.java   
private RemoteWebElement getIframe(Integer index) throws Exception {
  List<RemoteWebElement> iframes = getWebDriver().findElementsByCssSelector(
      "iframe,frame");
  try {
    return iframes.get(index);
  } catch (IndexOutOfBoundsException i) {
    throw new NoSuchFrameException(
        "detected " + iframes.size() + " frames. Cannot get index = " + index);
  }
}
项目:devtools-driver    文件:SetFrameHandler.java   
private RemoteWebElement getIframe(String id) throws Exception {
  RemoteWebElement currentDocument = getWebDriver().getDocument();

  String
      selector =
      "iframe[name='" + id + "'],iframe[id='" + id + "'],frame[name='" + id + "'],frame[id='" + id
      + "']";
  try {
    RemoteWebElement frame = currentDocument.findElementByCSSSelector(selector);
    return frame;
  } catch (NoSuchElementException e) {
    throw new NoSuchFrameException(e.getMessage(), e);
  }
}
项目:webtester2-core    文件:FocusSetterTest.java   
@Test
void switchingToFrameByUnknownNameOrIdThrowsException() {
    NoSuchFrameException exception = mock(NoSuchFrameException.class);
    when(webDriver.switchTo().frame("fooBar")).thenThrow(exception);
    assertThrows(NoSuchFrameException.class, () -> {
        cut.onFrame("fooBar");
    });
    verify(events).fireExceptionEvent(exception);
    verifyNoMoreInteractions(events);
}
项目:webtester2-core    文件:FocusSetterTest.java   
@Test
void switchingToFrameByNonFrameFragmentThrowsException() {
    PageFragment fragment = MockFactory.fragment().withName("The Name").build();
    NoSuchFrameException exception = mock(NoSuchFrameException.class);
    when(webDriver.switchTo().frame(fragment.webElement())).thenThrow(exception);
    assertThrows(NoSuchFrameException.class, () -> {
        cut.onFrame(fragment);
    });
    verify(events).fireExceptionEvent(exception);
    verifyNoMoreInteractions(events);
}
项目:SeleniumCucumber    文件:WaitHelper.java   
private WebDriverWait getWait(int timeOutInSeconds,int pollingEveryInMiliSec) {
    oLog.debug("");
    WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
    wait.pollingEvery(pollingEveryInMiliSec, TimeUnit.MILLISECONDS);
    wait.ignoring(NoSuchElementException.class);
    wait.ignoring(ElementNotVisibleException.class);
    wait.ignoring(StaleElementReferenceException.class);
    wait.ignoring(NoSuchFrameException.class);
    return wait;
}
项目:webtester-core    文件:WebDriverBrowserTest.java   
@Test(expected = NoSuchFrameException.class)
public void testExceptionHandlingInCaseAFrameIsNotFoundForTheGivenIndex() {

    TargetLocator locator = mockTargetLocator();
    NoSuchFrameException exception = createSeleniumExceptionOfClass(NoSuchFrameException.class);
    doThrow(exception).when(locator).frame(INDEX);

    try {
        cut.setFocusOnFrame(INDEX);
    } finally {
        verifyLastEventFiredWasExceptionEventOf(exception);
    }

}
项目:webtester-core    文件:WebDriverBrowserTest.java   
@Test(expected = NoSuchFrameException.class)
public void testExceptionHandlingInCaseAFrameIsNotFoundForTheGivenNameOrId() {

    TargetLocator locator = mockTargetLocator();
    NoSuchFrameException exception = createSeleniumExceptionOfClass(NoSuchFrameException.class);
    doThrow(exception).when(locator).frame(NAME_OR_ID);

    try {
        cut.setFocusOnFrame(NAME_OR_ID);
    } finally {
        verifyLastEventFiredWasExceptionEventOf(exception);
    }

}
项目:crawljax    文件:WebDriverBackedEmbeddedBrowser.java   
private void locateFrameAndgetSource(Document document, String topFrame, Element frameElement) throws NoSuchFrameException {
    String frameIdentification = "";

    if (topFrame != null && !topFrame.equals("")) {
        frameIdentification += topFrame + ".";
    }

    String nameId = DomUtils.getFrameIdentification(frameElement);

    if (nameId != null
            && !ignoreFrameChecker.isFrameIgnored(frameIdentification + nameId)) {
        frameIdentification += nameId;

        String handle = browser.getWindowHandle();

        LOGGER.debug("The current H: " + handle);

        switchToFrame(frameIdentification);

        String toAppend = browser.getPageSource();

        LOGGER.debug("frame dom: " + toAppend);

        browser.switchTo().defaultContent();

        try {
            Element toAppendElement = DomUtils.asDocument(toAppend).getDocumentElement();
            Element importedElement =
                    (Element) document.importNode(toAppendElement, true);
            frameElement.appendChild(importedElement);

            appendFrameContent(importedElement, document, frameIdentification);
        } catch (DOMException | IOException e) {
            LOGGER.info("Got exception while inspecting a frame:" + frameIdentification
                    + " continuing...", e);
        }
    }
}
项目:darcy-webdriver    文件:WebDriverBrowser.java   
/**
 * Wrapper for interacting with a targeted driver that may or may not actually be present.
 */
private void attempt(Runnable action) {
    try {
        action.run();
    } catch (NoSuchFrameException | NoSuchWindowException | NoSuchSessionException e) {
        throw new FindableNotPresentException(this, e);
    }
}
项目:darcy-webdriver    文件:WebDriverBrowser.java   
/**
 * Wrapper for interacting with a targeted driver that may or may not actually be present.
 * Returns a result.
 */
private <T> T attemptAndGet(Supplier<T> action) {
    try {
        return action.get();
    } catch (NoSuchFrameException | NoSuchWindowException | NoSuchSessionException e) {
        throw new FindableNotPresentException(this, e);
    }
}
项目:kuali_rice    文件:WebDriverUtil.java   
protected static void selectFrameSafe(WebDriver driver, String locator) {
    try {
        driver.switchTo().frame(locator);
    } catch (NoSuchFrameException nsfe) {
        // don't fail
    }
}
项目:BrainBridge    文件:Service.java   
/**
 * Serves the given request of the given client.
 * 
 * @param request
 *            The request to serve
 * @param clientSocket
 *            The client to serve
 * @throws IOException
 *             If an I/O-Exception occurs
 * @throws WindowHandleNotFoundException
 *             If a window handle could not be found
 */
private void serveRequest(final String request, final Socket clientSocket) throws IOException {
    try {
        // Reject the request if empty
        if (request == null || request.trim().length() <= 0) {
            HttpUtil.sendError(EHttpStatus.BAD_REQUEST, clientSocket);
            return;
        }

        // Reject the request if not a GET request
        final Pattern requestPattern = Pattern.compile(GET_REQUEST_PATTERN);
        final Matcher requestMatcher = requestPattern.matcher(request);
        if (!requestMatcher.matches()) {
            HttpUtil.sendError(EHttpStatus.BAD_REQUEST, clientSocket);
            return;
        }

        // Strip the content of the GET request
        final String requestContent = requestMatcher.group(1);

        // Serve create requests
        final boolean isCreateRequest = requestContent.startsWith(CREATE_REQUEST);
        if (isCreateRequest) {
            serveCreateRequest(clientSocket);
            return;
        }

        // Serve post message requests
        final boolean isPostMessageRequest = requestContent.startsWith(POST_MESSAGE_REQUEST);
        if (isPostMessageRequest) {
            servePostMessageRequest(requestContent, clientSocket);
            return;
        }

        // Serve get message requests
        final boolean isGetMessageRequest = requestContent.startsWith(GET_MESSAGE_REQUEST);
        if (isGetMessageRequest) {
            serveGetMessageRequest(requestContent, clientSocket);
            return;
        }

        // Serve shutdown requests
        final boolean isShutdownRequest = requestContent.startsWith(SHUTDOWN_REQUEST);
        if (isShutdownRequest) {
            serveShutdownRequest(requestContent, clientSocket);
            return;
        }

        // Request type not supported
        HttpUtil.sendError(EHttpStatus.NOT_IMPLEMENTED, clientSocket);
    } catch (final WindowHandleNotFoundException | StaleElementReferenceException | TimeoutException
            | NoSuchElementException | NoSuchFrameException | UnexpectedUnsupportedEncodingException e) {
        // Log the error and reject the request
        this.mLogger.logError("Server error while serving request: " + LoggerUtil.getStackTrace(e));
        HttpUtil.sendError(EHttpStatus.INTERNAL_SERVER_ERROR, clientSocket);
    }
}
项目:webtester2-core    文件:FocusSetter.java   
/**
 * Sets the browser's focus to the frame with the given index.
 *
 * @param index the index of the frame to focus on
 * @throws NoSuchFrameException in case there is no frame with the given index
 * @see WebDriver.TargetLocator#frame(int)
 * @since 2.0
 */
public void onFrame(int index) throws NoSuchFrameException {
    ActionTemplate.browser(browser())
        .execute(browser -> doOnFrame(browser, index))
        .fireEvent(browser -> new SwitchedToFrameEvent(index));
    log.debug("focused on frame with index: {}", index);
}
项目:webtester2-core    文件:FocusSetter.java   
/**
 * Sets the browser's focus to the frame with the given name or ID.
 *
 * @param nameOrId the name or ID of the frame to focus on
 * @throws NoSuchFrameException in case there is no frame with the given name or ID
 * @see WebDriver.TargetLocator#frame(String)
 * @since 2.0
 */
public void onFrame(String nameOrId) throws NoSuchFrameException {
    ActionTemplate.browser(browser())
        .execute(browser -> doOnFrame(browser, nameOrId))
        .fireEvent(browser -> new SwitchedToFrameEvent(nameOrId));
    log.debug("focused on frame with name or ID: {}", nameOrId);
}
项目:webtester2-core    文件:FocusSetter.java   
/**
 * Sets the browser's focus to the frame of the given {@link PageFragment page fragment}.
 *
 * @param frame the page fragment representing the frame to focus on
 * @throws NoSuchFrameException in case there is no frame with the given name or ID
 * @see WebDriver.TargetLocator#frame(String)
 * @since 2.0
 */
public void onFrame(PageFragment frame) throws NoSuchFrameException {
    ActionTemplate.browser(browser())
        .execute(browser -> doOnFrame(browser, frame))
        .fireEvent(browser -> new SwitchedToFrameEvent(frame));
    log.debug("focused on frame page fragment: {}", frame);
}
项目:kc-rice    文件:WebDriverUtils.java   
/**
 * <p>
 * Select frame defined by locator without throwing an Exception if it doesn't exist.
 * </p>
 *
 * @param driver to select frame on
 * @param locator to identify frame to select
 */
public static void selectFrameSafe(WebDriver driver, String locator) {
    try {
        driver.switchTo().frame(locator);
    } catch (NoSuchFrameException nsfe) {
        // don't fail
    }
}
项目:rice    文件:WebDriverUtils.java   
/**
 * <p>
 * Select frame defined by locator without throwing an Exception if it doesn't exist.
 * </p>
 *
 * @param driver to select frame on
 * @param locator to identify frame to select
 */
public static void selectFrameSafe(WebDriver driver, String locator) {
    try {
        driver.switchTo().frame(locator);
    } catch (NoSuchFrameException nsfe) {
        // don't fail
    }
}