0

Im having an issue with my tests where I select a button and then switch to the windwo that opens after i select the button, the issue is having is that i keep getting no frame exceptions and Out of bounds exception.

My code is:

        clickWithActions(driver, launchNote);
        sleepForTime(6000);
        Set<String> handles = driver.getWindowHandles();

        List list = Arrays.asList(handles.toArray());
        driver.switchTo().window(list.get(1).toString());
        sleepForTime(6000);
        driver.manage().window().maximize();
        driver.manage().window().setSize(new Dimension(1920, 1080));

        break;

Is there any way that i can wait for this window to appear first with out long waits?

FearghalQA
  • 255
  • 1
  • 2
  • 11

2 Answers2

1

There is this numberOfWindowsToBe() expected wait condition that sounds fitting here:

clickWithActions(driver, launchNote);

// wait for the number of windows to increase
new WebDriverWait(driver, 15).until(ExpectedConditions.numberOfWindowsToBe(2));
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
1

Before performing clickWithActions() you need to collect the initial WindowHandle and once you perform click you need to induce WebDriverWait for numberOfWindowsToBe(2). So your effective code block will be:

String first_handle = driver.getWindowHandle();
clickWithActions(driver, launchNote);
new WebDriverWait(driver,10).until(ExpectedConditions.numberOfWindowsToBe(2));
Set<String> allHandles = driver.getWindowHandles();
for(String winHandle:allHandles)
{
    if (!first_handle.equalsIgnoreCase(winHandle)
    {
    driver.switchTo().window(winHandle);
    }
}

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352