JYOTI SOMANI
JYOTI SOMANI

Reputation: 11

How to open new tab in selenium 3.141.59

In selenium 3.141.59 I am trying to open a new Tab using

 Actions action = new Actions(driver);
 action.keyDown(Keys.CONTROL).sendKeys(Keys.TAB).build().perform(); 
and  
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t"); 

I'm not able to open new Tab

Upvotes: 0

Views: 543

Answers (2)

Mehra Parv
Mehra Parv

Reputation: 1

This might help! this opens up the new tab and control passes to the newly opened tab.

 WebDriver driver = new FirefoxDriver();
       driver.get("http://www.google.com/");
       driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
       System.out.println(driver.getTitle());
       Thread.sleep(3000L);

       WebElement element = driver.findElement(By.linkText("Gmail"));

       Actions action = new Actions(driver);

       action.moveToElement(element);


       action.keyDown(Keys.CONTROL);
       action.click();

       action.keyDown(Keys.CONTROL).build().perform();
       Thread.sleep(2000L);
       ArrayList<String> list = new ArrayList<String>(driver.getWindowHandles());
       driver.switchTo().window(list.get(1));

       driver.get("http://www.yahoo.com/");
       Thread.sleep(4000L);
       driver.close();

Upvotes: 0

cruisepandey
cruisepandey

Reputation: 29382

You can try with this code :

((JavascriptExecutor) driver).executeScript("window.open('"+url+"','_blank');");

URL is a variable, You can use your own or else paste the value of it.

Upvotes: 1

Related Questions