The way I figure out for selenium 2, work fine for Chrome and firefox, IE has security check issue:
Set<String> winSet = webDriver.getWindowHandles();
List<String> winList = new ArrayList<String>(winSet);
String newTab = winList.get(winList.size() - 1);
webDriver.close(); // close the original tab
webDriver.switchTo().window(newTab); // switch to new tab
More Related Contents:
- What is the difference between ChromeDriver and WebDriver in selenium?
- Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click
- Element MyElement is not clickable at point (x, y)… Other element would receive the click
- How to switch to the new browser window, which opens after click on the button?
- WebDriver – wait for element using Java
- Selenium WebDriver How to Resolve Stale Element Reference Exception?
- How to handle windows file upload using Selenium WebDriver?
- Unable to import org.openqa.selenium.WebDriver using Selenium and Java 11
- WebDriver: check if an element exists? [duplicate]
- WebDriver open new tab
- pageLoadTimeout in Selenium not working
- The type FluentWait is not generic; it cannot be parameterized with arguments error for FluentWait Class through Selenium and Java
- Selenium WebDriver: Wait for complex page with JavaScript to load
- Equivalent of waitForVisible/waitForElementPresent in Selenium WebDriver tests using Java?
- Is there a way to use Selenium WebDriver without informing the document that it is controlled by WebDriver?
- Difference between webdriver.get() and webdriver.navigate()
- Driver executable must be set by the webdriver.ie.driver system property
- How do I protect the ports that chromedriver use?
- org.openqa.selenium.WebDriverException: chrome not reachable – when attempting to start a new session
- Selenium WebDriver and DropDown Boxes
- Using Selenium how to get network request [closed]
- Tools for measuring UI Performance [closed]
- java.lang.IllegalAccessError: tried to access method com.google.common.util.concurrent.SimpleTimeLimiter. when using Selenium-Java 3.5.1 or above
- java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;I)V with IE and Selenium through Java
- How to Conceal WebDriver in Geckodriver from BotD in Java?
- Why do some elements exist but not interactable/displayed?
- How to open a link in new tab (chrome) using Selenium WebDriver?
- Exception in thread “main” java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)
- How do you use a firefox plugin within a selenium webdriver program written in java?
- How to set proxy authentication in PhantomJS using selenium?