• Tech Travel Hub is your one stop, ultimate tour guide to all things tech, travel, visas and digital nomads
  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact
Menu
  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact
View Blog
May 2, 2023May 2, 2023

How To Handle Keyboard and Mouse Operation In Selenium Via Action class?

Keyboard and Mouse operations are two integral part of any application. More the reach UI more the complex operation. Here is a list of methods of action classe that is supported by Selenium in order to handle Mouse and Keyboard operations.

Keyboard Operations:

 

 

 

 

Operation        SyntaxUsage
KeyBoard        sendkeys()It sends the string to the locator 
keyDown(keys modifier)Takes the modifier key(shift,alt,control) as parameter and modifies the keykeys.SHIFT
keys.ALT
keys.CONTROL
The exception generated is IllegalArgumentException
keyDown(WebElement element,keys modifierKey)Another flavor of the keyDown which the modifier key press action is performed on a webElement.  
keyUpIt is used to simulate the modifier key up or key release action. This methods needs to be invoked after a keyDown method 
keyUp(WebElement element,keys modifierKey)Another flavor of the keyUp which the modifier key release action is performed on a webElement.  
sendKeys(CharacterSequence keysToSend)It is used when we need to send sequence of keys to a currently focused webElement. It is helpful when using modifier keys and that can not be released on the element. 
sendKeys(WebElement element,CharacterSequence keysToSend)Sends a sequence of keys to a webElement. 
WebElement textbox=driver.findElement(By.locator_of_textbox);
Action builder=new Action(driver);
Action typeInCAPS=builder.keyDown(textbox,keys.SHIFT);
.sendkeys(textbox,"abc");
.keyup(textbox,keys.SHIFT);
.build();
typeInCAPS.perform();

Mouse operations:

 

 

 

 

Operation        SyntaxUsage
Mouse        Click()It clicks on the current mouse pointerBest when used with mouse and keyboard events. Mostly a composite events
Click(WebElement element)It clicks on the middle of the webelement that is passed as a parameter. 
ClickAndHold()Performs a click method without releasing the mouse button  
ClickAndHold(WebElement element)It is used to Performs a click method without releasing the mouse button on a webelement 
ContextClick()Performs a right click operation in the current location of the mouse. 
ContextClick(WebElement element)Performs a right click operation in the current location of the mouse on an element. 
doubleClick()Performs a double click operation in the current location of the mouse. 
doubleClick(WebElement element)Performs a double click operation in the current location of the mouse on an element. 
dragAndDrop(WebElement fromElement,WebElement toElement)Performs a drag and drop method from one element to other. 
dragAndDropBy(WebElement fromElement, xoffset,int yoffset)performs drag and drop from element to a x,y positionClicks on the webelement and drag to the x,y location and drops it
moveByOffset(int xoffset,int yoffset)Performs a move operation of the mouse pointer based on x and y 
moveToElement(WebElement toElement)Performs a move operation to the webelement,  
moveToElement(WebElement element,int xoffset,int yoffset)Performs a right click operation in the current location of the mouse on an element.x,y calculation is done from the top left corner of the webelemnt specified.
release()Releases the pressed left mouse button at the current mouse position. 
release(WebElement element)Releases the pressed left mouse button to an webelement 
build()Generates the composite action 
WebElement rtClickElement=driver.findElement(By.locator_of_element);
Action rightClick=new Action(driver).contextClick(rtClickElement);
rightClick.build().perform()

one more example can be as follows

WebElement fromElement=driver.findElement(By.locator_of_fromElement);
WebElement toElement=driver.findElement(By.locator_of_toElement);
Action builder=new Action(driver)
Action dragAndDrop=builder.clickAndHold(fromElement)
.moveToElement(toElement)
.release(toElement)
.build();
dragAndDrop.perform();

Last item in this category is to discuss the Drag and Drop. With rich web interface,drag able web elements are very common now a days.Using Action class (an interface which represents a single user interaction) we can simulate the same thing while testing.

 

Post navigation

Previous post
Next post

Umer Umer

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • The Core Element Of A Woocommerce Store And 5 Incredible Plugins
  • 15 Amazing Must-Have WooCommerce Plugins in 2021
  • How to Make A MP4 File Smaller Using Wondershare UniConverter – 5 Important Tips
  • Wondershare Filmii – Create Videos Easily with AI-Powered Video Editor With 4 Important Tips
  • 10 Wonderful Places in India

Categories

  • Adventure
  • Agile Methodology
  • AI
  • All world Tour
  • Android Development
  • Ansible
  • App
  • App Development
  • Artificial Intelligence
  • AWS
  • Bitcoin
  • BlockChain
  • Blogging
  • Box Packing
  • Business
  • business
  • Business Communication
  • buying guide
  • C
  • car
  • Care
  • Certification
  • Certification
  • Chatbot
  • cinema
  • Cloud Tech
  • Content Marketing
  • Corporate
  • covid-19
  • crucible
  • Cryptocurrency
  • Database
  • DevOps
  • DevOps
  • Digital Marketing
  • Drawing
  • Dress
  • Earn Money Online
  • Educational
  • Employment
  • Entertainment
  • Exceptions In Java
  • Fashion
  • Festivals
  • Finance
  • Fitness
  • Food
  • Game
  • Gift ideas
  • Graphic Designers
  • Groovy
  • Health
  • Health
  • home
  • home improvement
  • HR
  • IllegalThreadStateException in Java
  • India Tour
  • Instagram
  • Ios
  • ISO
  • Java
  • Javascript
  • job
  • Kids Section
  • Kitchen
  • Law
  • Life Style
  • Lifestyle
  • Lifestyle Home Improvement
  • Magento
  • Main Stories
  • Management
  • Mattress
  • Motorable
  • Movie
  • nursing
  • Office Productivity
  • Pendrive
  • Perspective
  • Pet
  • Popular
  • Programming
  • Python
  • RDT
  • Relationships
  • Selenium
  • SEO
  • Skin
  • SOA
  • SOAPUI
  • Social Media
  • Social Media Marketing
  • Software
  • software development
  • Software Development Model
  • Software Engineering
  • Software Testing
  • Sports
  • Startup
  • T Robot
  • TDD
  • Tech
  • Tech News
  • Tech News
  • Technology
  • Tool
  • Tour Guide
  • Tour Guide
  • Travel
  • UFT
  • Uncategorized
  • USB Cable
  • VBscript
  • VPN
  • Web Development
  • WebHosting
  • WebServices
  • Wildlife
  • Wordpress
  • Yoga
  • Youtube

Tags

Instagram Instagram Marketing Marketing SEO Thoptv App

Categories

  • Tech
  • Travel
  • Visas
  • Digital Nomad
  • Tech
  • Travel
  • Visas
  • Digital Nomad

Publishing

If you would like to publish on our site, please email admin@techtravelhub.com

Quick Links

  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact
  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact

Contact

Tech Travel Hub LLC

Address:
8 The Green STE A
Dover
Delaware, 19901

Phone: +1 302 956 9948