0

I am logging in to my application (IE browser). On Home page, it has consumer link. I am clicking it.. It will open another window.. Enter the consumer id (mandatory field alone) and save. It is getting saved.

Now If I wanted to view the saved consumer. I need to close the window and need to transfer the control to Home page. I am trying by driver.switchTo.defaultContent() after closing the window. But it is NOT changing the control. the below error is returned..

Exception:

Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Unable to get browser (WARNING: The server did not provide any stacktrace information)

Code:

import java.io.File;
import java.io.IOException;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;

public class FirstTest {

    public static void main(String[] args) throws IOException, InterruptedException {
        // TODO Auto-generated method stub
        File file = new File("IEDriverServer.exe");
        System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
        WebDriver driver = new InternetExplorerDriver();        
        driver.get("http://xx.xxx.xxx.xx/mysuite/Login.aspx");
        driver.findElement(By.id("txtUser")).sendKeys("administrator");
        driver.findElement(By.id("txtPwd")).sendKeys("password");
        driver.findElement(By.id("cmdLogin")).click();      
        //Click Add customer (customer child window opens)
        driver.findElement(By.linkText("Add Customer")).click();
        driver.switchTo().window("Customer");
        //Enter Customer ID and Save
        driver.findElement(By.id("txtCode")).sendKeys("1234");
        driver.findElement(By.id("cmdPageSave")).click();
                //Close the child window
        driver.findElement(By.id("cmdPageClose")).click();
        //swith back to parent window
        driver.switchTo().defaultContent();
        Thread.sleep(3000);
        driver.findElement(By.linkText("All customers")).click();




    }

}
2
  • Are you doing this in the same tab or two tabs? Commented Apr 16, 2015 at 10:23
  • does your window gets refreshed when u click the consumer link. Commented Apr 16, 2015 at 12:03

1 Answer 1

2

Try storing handler name before switching.

public static void main(String[] args) throws IOException, InterruptedException {
        // TODO Auto-generated method stub
        File file = new File("IEDriverServer.exe");
        System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
        WebDriver driver = new InternetExplorerDriver();        
        driver.get("http://xx.xxx.xxx.xx/mysuite/Login.aspx");
        driver.findElement(By.id("txtUser")).sendKeys("administrator");
        driver.findElement(By.id("txtPwd")).sendKeys("password");
        driver.findElement(By.id("cmdLogin")).click();      
        //Click Add customer (customer child window opens)
        driver.findElement(By.linkText("Add Customer")).click();

        //Store before switch    
        String  mainHandle= driver.getWindowHandle();

        driver.switchTo().window("Customer");

        //Enter Customer ID and Save
        driver.findElement(By.id("txtCode")).sendKeys("1234");
        driver.findElement(By.id("cmdPageSave")).click();
                //Close the child window
        driver.findElement(By.id("cmdPageClose")).click();
        //swith back to parent window

        driver.switchTo().window(mainHandle);

        Thread.sleep(3000);
        driver.findElement(By.linkText("All customers")).click();

    }
Sign up to request clarification or add additional context in comments.

1 Comment

This is i have tried.. NO such window expection is thrown

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.