'How to open a new blank window using webdriver in java.

I am using (Webdriver) driver.close(to close the browser instead of using driver.quit). After the browser window is closed i am not able to use driver.get(url) -which throws unreachableBrowserException.

As a work around i am trying to get windowHandles.size(), when it is zero i want to open a new blank window and then use driver.get(url).

But i cound'not find any methods to open a blank window in Webdriver class.



Solution 1:[1]

Use below code..what ever the browser you user. use it like this after the closing the current browser session.

driver = new InternetExplorerDriver()/firefoxdriver();
driver.get("Url");

Solution 2:[2]

Once it's quit, the browser is gone - you are left with a driver instance that is unusable.

Unless you declare a new instance and assign it back to it. For example:

driver.findElement(By.id("a"); // doing something
driver.Quit(); // test is over, closing the browser
driver = new FirefoxDriver(); // you will need to give it a new driver to work with.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Umamaheshwar Thota
Solution 2 Arran