I've got a problem with error: org.openqa.selenium.NoSuchWindowException: no such window: window was already closed

Viewed 21

When i clicked on loginBtn, then first site is closing and another opening. Then if I try to find something by any selector->org.openqa.selenium.NoSuchWindowException: no such window: window was already closed:/ I've no idea what's going on.I was trying to find iFRame, switch to another window and still getting error.

That's the flow of test:

          @Test
            public void LogIn() throws AWTException, InterruptedException {
                MainPage mainPage= new MainPage();
                mainPage.logIn()
                        .loginToProfile()
                        .writeNameAndPassword()
                        .clickLoginBtn()
                        .clickWizyty();<--here is the problem
     }}
        
        

this is method which goes to another page:

     public OnMySite clickLoginBtn() {

            loginBtn.click();
            return new OnMySite();
    }

and here is the problem, on everything i getting exception

    public void  clickWizyty() throws InterruptedException {

        Thread.sleep(3000);
          //WebElement iFrame= DriverManager.getWebDriver().findElement(By.tagName("iframe"));
          //DriverManager.getWebDriver().switchTo().frame(iFrame);
            String currentTabHandle = DriverManager.getWebDriver().**getWindowHandle()**;
            String newTabHandle = DriverManager.getWebDriver().getWindowHandles()
                    .stream()
                    .filter(handle -> !handle.equals(currentTabHandle))
                    .findFirst()
                    .get();
            WaitForElement.waitUntilElemembtIsVisible(wizyty);
            wizyty.click();
    }}'''

even here: getWindowHandle(); its showing "no such window... "

0 Answers
Related