0

In years it is the first time I saw something like this, when I do a:

config.getWebDriver().getWindowHandles().size()

The result is always 1, but in fact, there is a main window opened and after a click, a popup opens.

My code may not help, because it is a javascript (server side) doing something I do not know on a 'onchange' event. I am trying to debug in Developer Tools, but it is being a tought activity. Here is the code anyway:

try {
        webActions.getFrameAndSwitchView(VidaNovaConstants.XPATH_FRAME_CRITICAS, config.getWebDriver());
        List<WebElement> lstSelects = config.getWebDriver().findElements(By.xpath(VidaNovaConstants.XPATH_SELECT_LIBERACAO_CRITICAS));
        for (WebElement elem : lstSelects) {
            webActions.selectCombo(elem, "Sim");
            if(config.getWebDriver().getWindowHandles().size() > 1) {
                switchWindow(config.getWebDriver());
                if(webActions.exists("//span[contains(text(),'Dados da Crítica']", "Não foi aberta a janela para motivo da liberação.")) {
                    selectMotivoPopup("Liberação Técnica");
                    setJustificativa("Liberando devido necessidade operacional.");
                    clickBtnGravar();
                }
            }
        }
    } catch (Exception e) {
        logger.error("Erro ao liberar todas criticas na tela 9. " + e.getMessage());
        config.getReport().addStep("Erro ao liberar todas criticas na tela 9.");
        Assert.fail("Erro ao liberar todas criticas na tela 9.");
    }

Never goes inside my condition (if).

The question is, how can I recognize this popup, to switch to it and interact with its elements?

I have set IE capatilites like this, including JAVASCRIPT_ENABLED and HANLES_ALERTS as false:

private WebDriver createIE() {
    System.setProperty("webdriver.ie.driver",
            Paths.get("").toAbsolutePath().toString() + "\\src\\main\\resources\\drivers\\IEDriverServer.exe"); 
    DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
    ieCapabilities.setJavascriptEnabled(true);
    ieCapabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, BLANK_PAGE);
    ieCapabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, true);
    ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    ieCapabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
    ieCapabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
    ieCapabilities.setCapability(JAVASCRIPT_ENABLED, false);
    ieCapabilities.setCapability(HANLES_ALERTS, false);
    ieCapabilities.setCapability(REQUIREDWINDOWSFOCUS, true);
    InternetExplorerOptions opt = new InternetExplorerOptions(ieCapabilities);
    webDriver = new InternetExplorerDriver(opt);
    webDriver.manage().deleteAllCookies();
    webDriver.manage().window().maximize();
    return webDriver;
}

Any suggestions would help a lot on how to handle this situation.

  • What kind of "pop-up" is it? An alert? A modal? A new browser window? – Lee Jensen Sep 3 at 22:07
  • It is a new browser window, but 'modified' due to javascripts doing sth's... There is no field to input addresss as an example. – Leonardo Leonardo Sep 4 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.