- 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 can I handle multiple keyboard keys using Selenium Webdriver?
We can handle multiple keyboard keys in Selenium webdriver by using the method Keys.chord. The multiple keyboard keys to be handled are passed as parameters to this method.
The return type of the Keys.chord method is a string and can be applied to an element with the help of the sendKeys method. For example, in order to perform a select operation on text entered inside an edit box we require the keys ctrl+a to be pressed simultaneously.
Syntax
String k = Keys.chord(Keys.CONTROL, "A"); driver.findElement(By.name("q")).sendKeys(k);
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 MultipleKeys{ 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.google.com/"); //identify element WebElement l = driver.findElement(By.name("q")); l.sendKeys("Java"); // method Keys.chord String k = Keys.chord(Keys.CONTROL, "A"); //handling multiple keys l.sendKeys(k); } }
Output
- Related Articles
- How can we handle authentication popup in Selenium WebDriver using Java?
- How to handle frame in Selenium WebDriver using java?
- How to handle windows file upload using Selenium WebDriver?
- How to handle SSL certificate error using Selenium WebDriver?
- How to handle authentication popup with Selenium WebDriver using Java?
- How can I scroll a web page using selenium webdriver in python?
- How can I close a specific window using Selenium WebDriver with Java?
- How can I select date from a datepicker div using Selenium Webdriver?
- How can I clear text of a textbox using Python Selenium WebDriver?
- How can I verify Error Message on a webpage using Selenium Webdriver?
- Handle Firefox Not Responding While Using Selenium WebDriver With Python?
- How can I get Webdriver Session ID in Selenium?
- How does Selenium Webdriver handle SSL certificate in Firefox?
- How does Selenium Webdriver handle SSL certificate in Chrome?
- How to handle frames in Selenium Webdriver in Python?

Advertisements