Vera Naverniuk
Vera Naverniuk

Reputation: 11

Program fails trying to re-get window handle when switching between browser tabs

Could somebody help me please! What is the problem here: I'm working with selenide, writing autotests using java and I need to switch between different tabs in browser or between its windows from time to time. I use the same method for it, switchWindowTab(). But when the program switch tabs for the first time it works correctly and for the second one it fails on the 2d or 3d line when it's trying to implement getWindowHandles() or getWindowHandle():

If it fails on getWindowHandles(), it print - UnreachableBrowserException: Error communicating with the remote browser. It may have died.

and if it happens on getWindowHandle() it prints - NoSuchWindowException

What can be the reason for it? And how can I deal with it?

 public void switchWindowTab(){
        ArrayList<String> tabs = new ArrayList<>(driver.getWindowHandles());
        String currentHandle = driver.getWindowHandle();
        for(String tab: tabs) {
            if (!tab.equalsIgnoreCase(currentHandle))
                Selenide.switchTo().window(tab, Duration.ofSeconds(120));
        }
    }

Can it be connected with switching between windows? As just before program fails it switches to a plugin window which closes got all the permission. So the program returns to the first window within this action.

The program fail often, but not all the time, sometimes (very rare) it works fine anyway.

And also as I know, the problem exist only when running the program locally.

Upvotes: 1

Views: 225

Answers (0)

Related Questions