- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
How to open a link in new tab of chrome browser using Selenium WebDriver?
We can open a link in the new tab of Chrome browser using Selenium webdriver using the methods Keys.chord and sendKeys. The method Keys.chord is used to send multiple keys simultaneously as parameters.
To open a new tab, the Keys.CONTROL and Keys.ENTER are passed as parameters to the Keys.chord. Finally, the Keys.chord is passed as a parameter to the sendKeys.
Let us click on the Jobs links in a new tab, highlighted in the below image −
Syntax
String l = Keys.chord(Keys.CONTROL,Keys.ENTER); driver.findElement(By.xpath ("//a[@title='Job @ Tutorials Point']")).sendKeys(l);
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Keys; public class ElementLocator{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); //implicit wait driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //URL launch driver.get("https://www.tutorialspoint.com/index.htm"); //Keys.chord string String l = Keys.chord(Keys.CONTROL,Keys.ENTER); //open in a new tab driver.findElement(By.xpath ("//a[@title='Job @ Tutorials Point']")).sendKeys(l); } }
Output
- Related Articles
- How to open a link in new tab using Selenium WebDriver?
- How to open a new tab using Selenium WebDriver?
- How to open new tab in same browser and switch between them using Selenium?
- How to open a new window on a browser using Selenium WebDriver for python?
- Open New Browser Tab in Selenuim
- How do I open Chrome in selenium WebDriver?
- How to connect to an already open browser using Selenium Webdriver?
- Using the Selenium WebDriver - Unable to launch chrome browser on Mac
- How to open a browser window in full screen using Selenium WebDriver with C#?
- How to open browser window in incognito/private mode using python selenium webdriver?
- Is there any way to load an extension in chrome browser using Selenium Webdriver?
- How to run Selenium tests on Chrome Browser using?
- How to click on a link using Selenium webdriver in Python.
- How to launch Chrome Browser via Selenium?
- How to close child browser window in Selenium WebDriver using Java?

Advertisements