How to open a new tab in IE using selenium (java) and open the url on this tab (not the window)

How to open a new tab in IE using selenium (java) and open the url on this tab (not the window)? Am I using the code below to open a new tab?

driver.get("https://google.com/"); //below line of code opens a new tab but does sets control on new tab. driver.findElement(By.cssSelector("Body")).sendKeys(Keys.CONTROL + "t");//opens new tab // As control does not sets on new tab, the below link opens on first tab only.. driver.get("https://facebook.com/");//but load facebook in first tab ie on google page 

Can someone tell me how to switch control to a new tab so that the facebook link opens in this new tab.

Hi

I am using Selenium Web-Driver Version 2.40 and IE 11.0

 WebDriver driver = new InternetExplorerDriver(ieCapabilities); driver.manage().window().maximize(); driver.get("https://google.com/"); driver.findElement(By.cssSelector("Body")).sendKeys(Keys.CONTROL + "t");//opens new tab //Store the current window handle String winHandleBefore = driver.getWindowHandle(); //Perform the click operation that opens new window //Switch to new window open for(String winHandle : driver.getWindowHandles()){ driver.switchTo().window(winHandle); driver.get("https://facebook.com/"); } // Perform the actions on new window //Close the new window, if that window no more required driver.close(); //Switch back to original browser (first window) driver.switchTo().window(winHandleBefore); //continue with original browser (first window) 

I can not open facebook in a new tab of the same window.

Relations Shashank Goyal

+3
java selenium tabs
Apr 02 '14 at 18:55
source share
2 answers

You will need to use

 driver.switchTo().window(String) 

to go to the window that appeared the same as when you open a new window.

+1
Apr 02 '14 at 18:58
source share
 ArrayList<String> tabHandles1 = new ArrayList<String>(driver.getWindowHandles()); driver.switchTo().window(tabHandles1.get(index)); 

u can pass a place to the index value or iterate over the entire tab using the handle labels arrayList1

0
Jul 14 '16 at 19:07
source share



All Articles