- 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
How to open a link in new tab using Selenium WebDriver?
We can open a link in the new tab with Selenium. . The methods Keys.chord and sendKeys can be used for this. The Keys.chord method allows you to pass multiple keys simultaneously.
We shall send Keys.CONTROL and Keys.ENTER as arguments to the Keys.chord method. Then the complete string is then passed as an argument to the sendKeys method. Finally, the sendKeys method has to be applied on the link which is identified by driver.findElement method.
Syntax
String clicklnk = Keys.chord(Keys.CONTROL,Keys.ENTER); driver.findElement(By.xpath("//*[text()='Privacy Policy']")). sendKeys(clicklnk);
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; public class OpenInNwTab{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://www.tutorialspoint.com/about/about_careers.htm"); // wait of 4 seconds driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); // Keys.Chord string String clicklnk = Keys.chord(Keys.CONTROL,Keys.ENTER); // open the link in new tab, Keys.Chord string passed to sendKeys driver.findElement( By.xpath("//*[text()='Privacy Policy']")).sendKeys(clicklnk); } }
Output
- Related Articles
- How to open a link in new tab of chrome browser 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?
- How to click on a link using Selenium webdriver in Python.
- How to open link in a new window - JavaScript?
- Open New Browser Tab in Selenuim
- How to connect to an already open browser using Selenium Webdriver?
- 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?
- How do I open Chrome in selenium WebDriver?
- How do I change focus to a new popup tab in Selenium?
- How to Verify Tooltip using Selenium WebDriver?
- How to upload files using Selenium Webdriver?
- How to refresh a webpage using Python Selenium Webdriver?

Advertisements