kethan
kethan

Reputation: 17

Automatically closing of Current working window is quitting the driver

I want to perform the below steps

  1. Launch application
  2. Click on link on the application - new window opens 3.switch to new window and do required actions - window closed after doing required actions
  3. Switch to parent window and do the remaining actions

But at point no 3 the driver is quitting it's instance and further steps are failing since driver instance is closed

Could someone please suggest me

Upvotes: 1

Views: 1256

Answers (1)

cruisepandey
cruisepandey

Reputation: 29382

Once you have clicked on a WebElement on Page1 , you would be redirected to Page2 , Now use this code :

        //Page1 some operations

        //click on a web element which redirects/opens a new tab/window

        ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
        driver.switchTo().window(tabs.get(1));

        //perform some operations on second tab/window

        driver.close(); // closing the Page2 windows or tab/windows

        driver.switchTo().window(tabs.get(0));

        //Now your webdriver has foucs on Page1 

       // do remaining operations on Page1  

Note that you should use only driver.close() when you are at second page , do not use driver.quit() as it would close the whole instance.

Upvotes: 1

Related Questions