Example usage for org.openqa.selenium NoSuchWindowException NoSuchWindowException

List of usage examples for org.openqa.selenium NoSuchWindowException NoSuchWindowException

Introduction

In this page you can find the example usage for org.openqa.selenium NoSuchWindowException NoSuchWindowException.

Prototype

public NoSuchWindowException(String reason) 

Source Link

Usage

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

License:Apache License

/**
 * {@inheritDoc}// ww w .  ja v a2 s  . com
 */
@Override
public INavigateSelenium navigateToWindowByPartialTitle(String title) {
    try {
        WebDriver popup;
        Iterator<String> windowIterator = driver.getWindowHandles().iterator();
        while (windowIterator.hasNext()) {
            String windowHandle = windowIterator.next();
            popup = driver.switchTo().window(windowHandle);
            if (popup.getTitle().contains(title)) {
                break;
            }
        }
        logger.debug("navigateToWindowByPartialTitle : Navigated to window by:" + title);

    } catch (NoSuchWindowException nswe) {
        logger.error("navigateToWindowByPartialTitle : No Window found");
        throw new NoSuchWindowException("navigateToWindowByPartialTitle : No Window found");

    }
    return this;
}

From source file:com.consol.citrus.selenium.client.WebClient.java

License:Apache License

@Override
public void verifyPage(WebPage page) {
    if (!webDriver.getCurrentUrl().contains(page.getPageUrl())) {
        String errorMessage = "Expected page is <" + page.getPageUrl() + ">" + " but found <"
                + webDriver.getCurrentUrl() + ">.";
        throw new NoSuchWindowException(errorMessage);
    }//  ww w  .  j  ava2  s .  c  om
}

From source file:com.opera.core.systems.scope.services.ums.WindowManager.java

License:Apache License

public void setActiveWindow(String title) {
    Integer windowId = (Integer) xpathPointer(windows.values(), "/.[title='" + title + "']/windowID")
            .getValue();//w  w w .  ja  v a2 s.co  m
    if (windowId == null) {
        throw new NoSuchWindowException("No such window : " + title);
    }
    setActiveWindowId(windowId);
}

From source file:com.opera.core.systems.scope.stp.services.ScopeWindowManager.java

License:Apache License

public void setActiveWindow(String title) {
    Integer windowId = (Integer) xpathPointer(windows.values(), "/.[title='" + title + "']/windowID")
            .getValue();//from w w  w .j a  v a 2  s  .co m
    if (windowId == null) {
        throw new NoSuchWindowException("No such window: " + title);
    }
    setActiveWindowId(windowId);
}

From source file:com.redhat.darcy.webdriver.internal.CachingTargetedWebDriverTest.java

License:Open Source License

@Test
public void shouldCreateTargetedWebElementsThatReturnFalseForIsDisplayedIfCannotSwitchDriver() {
    WebDriver mockedDriver = mock(WebDriver.class);
    TargetLocator mockedTargetLocator = mock(TargetLocator.class);

    when(mockedDriver.switchTo()).thenReturn(mockedTargetLocator);
    when(mockedTargetLocator.window(anyString())).thenThrow(new NoSuchWindowException("No such window"));

    TargetedWebDriverFactory targetedDriverFactory = new CachingTargetedWebWebDriverFactory(mockedDriver,
            WebDriverTargets.window("test"));

    WebElement mockedElement = mock(WebElement.class);

    WebElement targetedWebElement = targetedDriverFactory
            .getTargetedWebDriver(WebDriverTargets.window("not-present"))
            .createTargetedWebElement(mockedElement);

    assertFalse(targetedWebElement.isDisplayed());
}

From source file:com.redhat.darcy.webdriver.internal.CachingTargetedWebDriverTest.java

License:Open Source License

@Test
public void shouldReturnFalseForIsPresentIfCannotSwitchToTargetWindow() {
    WebDriver mockedDriver = mock(WebDriver.class);
    TargetLocator mockedTargetLocator = mock(TargetLocator.class);

    when(mockedDriver.switchTo()).thenReturn(mockedTargetLocator);
    when(mockedTargetLocator.window(anyString())).thenThrow(new NoSuchWindowException("No such window"));

    TargetedWebDriverFactory targetedDriverFactory = new CachingTargetedWebWebDriverFactory(mockedDriver,
            WebDriverTargets.window("test"));

    TargetedWebDriver targetedDriver = targetedDriverFactory
            .getTargetedWebDriver(WebDriverTargets.window("not-present"));

    assertFalse(targetedDriver.isPresent());
}

From source file:org.uiautomation.ios.server.command.uiautomation.SetCurrentContextNHandler.java

License:Apache License

@Override
public Response handle() throws Exception {
    String context = getRequest().getPayload().getString("name");
    WorkingMode mode = null;//  www .  j  a  v a2s  .c o m
    if (context.startsWith(WorkingMode.Web.toString())) {
        mode = WorkingMode.Web;
    } else {
        mode = WorkingMode.valueOf(context);
    }
    getSession().setMode(mode);

    if (context.startsWith(WorkingMode.Web + "_")) {
        if (getSession().getRemoteWebDriver().getWindowHandles().isEmpty()) {
            throw new NoSuchWindowException("Cannot find a web view in the current app.");
        }
        if (WorkingMode.Web.toString().equals(context)) {
            getSession().setMode(WorkingMode.Web);
        } else {
            String pageId = context.replace(WorkingMode.Web + "_", "");

            // TODO freynaud. 2 windows doesnt mean 2 pages ...
            int delta = getSession().getRemoteWebDriver().getWindowHandleIndexDifference(pageId);
            if (delta != 0) {
                if (getSession().getApplication().isSafari()) {
                    getSession().getNativeDriver()
                            .executeScript("new SafariPageNavigator().enter().goToWebView(" + delta + ");");
                } else {
                    // TODO?
                }
            }
            getSession().getRemoteWebDriver().switchTo(pageId);
        }

    }
    // Set the current implicit wait timeout, if one has been set.
    // This is to persist the implicit wait timeout after switching to webview and back.
    if (SetImplicitWaitTimeoutNHandler.TIMEOUT != null) {
        // mocking a request to SET_TIMEOUT
        JSONObject payload = new JSONObject();
        payload.append("ms", SetImplicitWaitTimeoutNHandler.TIMEOUT);
        WebDriverLikeRequest wdlr = new WebDriverLikeRequest("POST", new Path(WebDriverLikeCommand.SET_TIMEOUT),
                payload);

        // set the timeout by 'handling' the request, we don't care about it's response.
        try {
            CommandMapping.SET_TIMEOUT.createHandler(getDriver(), wdlr).handle();
        } catch (Exception e) {
            // dump out any exception, but ignore it as the primary concern is switching context
            // which has succeeded if we got here
            e.printStackTrace();
        }
    }

    Response resp = new Response();
    resp.setSessionId(getSession().getSessionId());
    resp.setStatus(0);
    resp.setValue(new JSONObject());
    return resp;
}

From source file:org.uiautomation.ios.server.ServerSideSession.java

License:Apache License

private void checkWebModeIsAvailable() {
    if (webDriver != null) {
        return;//from ww  w.  j  ava  2 s  .  c  o  m
    } else {
        try {
            getNativeDriver().findElement(By.className("UIAWebView"));
        } catch (NoSuchElementException e) {
            throw new NoSuchWindowException("The app currently doesn't have a webview displayed.");
        }
    }

}