diff --git a/java/client/test/org/openqa/selenium/WindowSwitchingTest.java b/java/client/test/org/openqa/selenium/WindowSwitchingTest.java
index <HASH>..<HASH> 100644
--- a/java/client/test/org/openqa/selenium/WindowSwitchingTest.java
+++ b/java/client/test/org/openqa/selenium/WindowSwitchingTest.java
@@ -123,10 +123,11 @@ public class WindowSwitchingTest extends AbstractDriverTestCase {
     driver.findElement(By.name("windowThree")).click();
 
     driver.switchTo().window("result");
+    int currentWindowHandles = driver.getWindowHandles().size();
 
     try {
       driver.findElement(By.id("close")).click();
-      Set<String> allHandles = waitFor(windowHandleCountToBe(1));
+      Set<String> allHandles = waitFor(windowHandleCountToBe(currentWindowHandles - 1));
 
       assertEquals(1, allHandles.size());
     } finally {
EranMes: Making the window switching test slightly more accurate.

r<I>