System.setProperty(\"webdriver.chrome.driver\", \"D:\\\\softwares\\\\chromedriver_win32\\\\chromedriver.exe\");
WebDriver driver = new ChromeDriver();
driver.manage
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");
You can open multiple browser or a window by using below code:
WebDriver driver = new ChromeDriver();
driver.get("http://yahoo.com");
WebDriver driver1 = new ChromeDriver();
driver1.get("google.com");
WebDriver driver2 = new InternetExplorerDriver();
driver2.get("google.com/gmap");
I had used the below code to open a new tab in the browser using C# selenium..
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("window.open();");
for clicking on the link which expected to be opened from new tab use this
WebDriver driver = new ChromeDriver();
driver.get("https://www.yourSite.com");
WebElement link=driver.findElement(By.xpath("path_to_link"));
Actions actions = new Actions(driver);
actions.keyDown(Keys.LEFT_CONTROL)
.click(element)
.keyUp(Keys.LEFT_CONTROL)
.build()
.perform();
ArrayList<String> tab = new ArrayList<>(driver.getWindowHandles());
driver.switchTo().window(tab.get(1));
If you can get the link element you can use this. It will also take you to the tab that you have opened.
WebElement link= driver.findElement(By.tagname("a"));
String keyString = Keys.CONTROL+Keys.SHIFT.toString()+Keys.ENTER.toString());
link.sendKeys(keyString);
First open empty new Tab by using the keys Ctrl + t and then use .get() to fetch the URL you want. Your code should look something like this -
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,"t");
driver.findElement(By.tagName("body")).sendKeys(selectLinkOpeninNewTab);
driver.get("www.facebook.com");
If you want to open a link on the current view in a new tab then the code you've written above can be used. Instead of By.linkText()
make sure you use the appropriate By selector class to select the web element.