Thursday, 6 September 2018

What is the difference between Action and Actions in Selenium

Technically Action - is an interface and
Actions is a class.

We can use Actions class to perform complex actions such as drag and drop, click and hold, move to element, context click and double click, press keys (Control, ALT or Shift) or release them and so on.

Actions class support following methods (Important ones I have listed):

click() - click at current mouse position
click(WebElement) - click on web element passed. 
clickAndHold() - click and hold from current mouse position
clickAndHold(WebElement) - click and hold web element passed
contextClick() - context click at the current mouse position
contextClick(WebElement) - context click on web element
doubleClick() - double click at the current mouse position
doubleClick(WebElement) - double click on web element
dragAndDrop(WebElement source, WebElement target) - drag and drop from source to target. 
keyDown(java.lang.CharSequence key) -- Press modifier keys such as CTRL or ALT or SHIFT key.
keyUp(java.lang.CharSequence key) -- Release  modifier keys such as CTRL or ALT or  SHIFT keys. 
moveToElement(WebElement target) - move to web element passed. 
build() - generates composite action. Used after providing multiple actions. 
perform() - executes all composite actions. 
release() - release on the current mouse position. 
release(WebElement) - release on the target web element
sendKeys(java.lang.CharSequence... keys) - send keys such as ENTER, ARROW_DOWN and so on. 
sendKeys(WebElement target, java.lang.CharSequence... keys) -- send keys on web element such as ENTER, ARROW_DOWN and so on. 


Note:


  • The perform() method internally calls build() method, which returns Action interface and then calls perform defined in Action interface. 
  • So, either we can call build() method and then perform() method, or we can directly call perform() method without calling build() method. 




No comments:

Post a Comment

How to schedule RFT (Rational Functional Tester) scripts to run using Jenkins / schedule

How to schedule RFT (Rational Functional Tester) scripts to run using Jenkins / schedule 1. Create a batch file with following content ...