this below code works for me in Selenium 3 and chrome version 58.
WebDriver driver = new ChromeDriver();
driver.get("http://yahoo.com");
((JavascriptExecutor)driver).executeScript("window.open()");
ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(1));
driver.get("http://google.com");
More Related Contents:
- Selenium – Basic Authentication via url
- How to open a new tab using Selenium WebDriver in Java?
- java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property
- org.openqa.selenium.WebDriverException: unknown error: call function result missing ‘value’
- java.lang.IllegalStateException: The driver executable does not exist: while trying to execute tests through Selenium, ChromeDriver and Chrome
- How to handle authentication popup in Chrome with Selenium WebDriver using Java
- Set Chrome’s language using Selenium ChromeDriver
- How many ways to click on webElement In WebDriver?
- How to switch to the new browser window, which opens after click on the button?
- Do we have any generic function to check if page has completely loaded in Selenium
- How to handle windows file upload using Selenium WebDriver?
- Load Chrome Profile using Selenium WebDriver using java
- pageLoadTimeout in Selenium not working
- Cannot find firefox binary in PATH. Make sure firefox is installed
- Selenium WebDriver: Wait for complex page with JavaScript to load
- ChromeDriver and WebDriver for Selenium through TestNG results in 4 errors
- How to ignore protected Mode Settings for Internet Explorer using setCapability() through Selenium and Java?
- Find div element by multiple class names?
- Exception in thread “main” java.lang.IllegalStateException: The driver executable does not exist while running Selenium Test on Ubuntu
- File Upload using Selenium WebDriver and Java Robot Class
- Could not load extension from scoped_dir6312_32763/internal.Loading of unpacked extensions is disabled by the administrator with ChromeDriver Selenium
- java.lang.IllegalAccessError: tried to access method com.google.common.util.concurrent.SimpleTimeLimiter. when using Selenium-Java 3.5.1 or above
- “OsProcess checkForError : CreateProcess error=193, %1 is not a valid Win32 application” while starting Internet Explorer through Java and Selenium
- Take full page screenshot in Chrome with Selenium
- Selenium Webdriver – Stale element exception when clicking on multiple dropdowns while HTML DOM doesn’t change
- How to find the coordinates of the buttons on a canvas, and click on them after using Java and Selenium?
- How to resolve, Stale element exception? if element is no longer attached to the DOM?
- Error executing testng.xml through CLI : Could not find or load main class org.testng.TestNG
- How to scroll a specific DIV using Selenium WebDriver with Java?
- How to wait for an alert in Selenium webdriver ? [duplicate]