- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Open New Browser Tab in Selenuim
Answer − We can open a new browser tab in Selenium webdriver. The methods - Keys.chord and sendKeys are required to achieve this task. The Keys.chord method is used to send multiple keys at once.
We shall pass Keys.CONTROL and Keys.ENTER as parameters to this method. The complete string is again passed as a parameter to the sendKeys. Finally, the method sendKeys shall be applied on the link which we want to open in a new tab
Syntax
String l = Keys.chord(Keys.CONTROL,Keys.ENTER); driver.findElement(By.xpath("//*[text()='Links']")). sendKeys(l);
Code Implementation
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Keys; public class OpenNewTab{ public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); // wait of 5 seconds driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //url launch driver.get("https://www.tutorialspoint.com/about/about_careers.htm"); // Keys.Chord string String l = Keys.chord(Keys.CONTROL,Keys.ENTER); // open new tab driver.findElement(By.xpath("//*[text()='Terms of Use']")).sendKeys(l); } }
Output
- Related Articles
- How to open a link in new tab of chrome browser using Selenium WebDriver?
- How to open new tab in same browser and switch between them using Selenium?
- How to open a new tab using Selenium WebDriver?
- How to open a link in new tab using Selenium WebDriver?
- What's the best way to open new browser window using JavaScript?
- How to open a new window on a browser using Selenium WebDriver for python?
- Print new line and tab in Arduino
- How to close a current tab in a browser window using JavaScript?
- How to close active/current tab without closing the browser in Selenium-Python?
- How to use research tab for new video topics in YouTube
- Open a file browser with default directory in JavaScript and HTML?
- Sending an Intent to browser to open specific URL in Android?
- How to delete a localStorage item when the browser window/tab is closed?
- WhatsApp’s new ‘Status’ tab feature to share Images and Videos
- How do I change focus to a new popup tab in Selenium?

Advertisements