The keystrokes needed to open a new tab are platform-specific. In Windows, they are Control + T.
You can either:
- Open a new, empty tab by sending these keystrokes to the body of the document, or
- Open a link in a new tab by sending the keystrokes to the link
Opening a new, empty tab
Java
WebElement body = driver.findElement(By.tagName("body")); body.sendKeys(Keys.chord(Keys.CONTROL,"t"));
Python
body = driver.find_element_by_tag_name("body") body.send_keys(Keys.CONTROL + 't')
C#
IWebElement body = driver.FindElement(By.TagName("body")); body.SendKeys(Keys.Control + 't');
Opening a link in a new tab
Java
WebElement link = driver.findElement(By.linkText("My link text")); link.sendKeys(Keys.chord(Keys.CONTROL,"t"));
Python
link = driver.find_element_by_link_text("My link text") link.send_keys(Keys.CONTROL + 't')
C#
IWebElement link = driver.FindElement(By.LinkText("My link text")); link.SendKeys(Keys.Control + 't');