1

I've written a selenium test that navigates to a page, opens a link (in a new tab), switches to that tab and takes a screenshot. It's been working for months. Suddenly it doesn't. It seems that anything I try to do on this new tab after switching to it (interacting with elements, refreshing the page, navigating to a new page) results in a TimeOutException error.

I've tried waiting longer for the tab to load, I've tried navigating to the tab and refreshing before interacting with it (which lead me to find that I can't even do that much after the tab switch), I've tried changing my chrome and chromedriver versions (currently on Chrome v73 and chromedriver 2.46.628402). Still getting the TimeOutException.

Here's my code (with the screenshot code replaced with a refresh since it's the same result):

@Test 
public void ExternalLinkScreenshot() throws Exception{

    driver = getDriverByName(CHROME);

    WebDriverWait wait = new WebDriverWait(driver, 30);

    driver.navigate().to("www.mywebsite.com");
    wait.until(ExpectedConditions.elementToBeClickable(By.linkText("My Link")));
    driver.findElement(By.linkText("My Link")).click();
    TimeUnit.SECONDS.sleep(3);

    Set<String> handles = driver.getWindowHandles();
    String originalHandle = driver.getWindowHandle();

    for (String handle : handles) {

        if (!handle .equals(originalHandle))
        {
            driver.switchTo().window(handle); 

        } 

    }       

    driver.navigate.refresh(); 


    for(String handle : driver.getWindowHandles()) {

        if (!handle.equals(originalHandle)) { 

           driver.switchTo().window(handle); 

           driver.close(); 

        } 

    }

    driver.switchTo().window(originalHandle);
  • This question isn't asking how to switch to a new tab, but why that tab is unable to be interacted with once it's been switched to, which is already in the text of the question. – Nick Schuette Apr 15 '19 at 12:30

0 Answers0