Reputation: 17
I want to perform the below steps
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
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