Selenium Actions present in Selenium WebDriver class which is used to perform  user interaction operations.Like mouse mouse click ,double click drag and drop.Many a time we found that these operation are needed by Selenium WebDriver.To use this action class first we need to transfer the driver control to this class and then to perform action operation.

To create an object of action class we need to create an object of action class for creating an object the following code be written

Actions act=new Actions(driver);

To perform operation on an Web Element we needs to do user defined operations

    public static void main(String ar[]) {
        System.setProperty("webdriver.gecko.driver", "D:\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get("http://google.co.in");
        Actions act = new Actions(driver);
        WebElement we = driver.findElement(By.xpath(".//*[@id='hplogo']"));
        act.moveToElement(we).perform();
        act.contextClick(we).perform();
    }

NOTE-It will show the exception in Selenium 3 instead you can use Java Robot Class.

Modifier and TypeMethod and Description
Actionbuild()

Generates a composite action containing all actions so far, ready to be performed (and resets the internal builder state, so subsequent calls to build() will contain fresh sequences).

Actionsclick()

Clicks at the current mouse location.

Actionsclick(WebElement onElement)

Clicks in the middle of the given element.

ActionsclickAndHold()

Clicks (without releasing) at the current mouse location.

ActionsclickAndHold(WebElement onElement)

Clicks (without releasing) in the middle of the given element.

ActionscontextClick()

Performs a context-click at the current mouse location.

ActionscontextClick(WebElement onElement)

Performs a context-click at middle of the given element.

ActionsdoubleClick()

Performs a double-click at the current mouse location.

ActionsdoubleClick(WebElement onElement)

Performs a double-click at middle of the given element.

ActionsdragAndDrop(WebElement source, WebElement target)

A convenience method that performs click-and-hold at the location of the source element, moves to the location of the target element, then releases the mouse.

ActionsdragAndDropBy(WebElement source, int xOffset, int yOffset)

A convenience method that performs click-and-hold at the location of the source element, moves by a given offset, then releases the mouse.

ActionskeyDown(Keys theKey)

Performs a modifier key press.

ActionskeyDown(WebElement element, Keys theKey)

Performs a modifier key press after focusing on an element.

ActionskeyUp(Keys theKey)

Performs a modifier key release.

ActionskeyUp(WebElement element, Keys theKey)

Performs a modifier key release after focusing on an element.

ActionsmoveByOffset(int xOffset, int yOffset)

Moves the mouse from its current position (or 0,0) by the given offset.

ActionsmoveToElement(WebElement toElement)

Moves the mouse to the middle of the element.

ActionsmoveToElement(WebElement toElement, int xOffset, int yOffset)

Moves the mouse to an offset from the top-left corner of the element.

Actionspause(long pause)

Deprecated.

‘Pause’ is considered to be a bad design practice.

voidperform()

A convenience method for performing the actions without calling build() first.

Actionsrelease()

Releases the depressed left mouse button at the current mouse location.

Actionsrelease(WebElement onElement)

Releases the depressed left mouse button, in the middle of the given element.

ActionssendKeys(java.lang.CharSequence… keysToSend)

Sends keys to the active element.

ActionssendKeys(WebElement element, java.lang.CharSequence… keysToSend)

Equivalent to calling: Actions.click(element).sendKeys(keysToSend). This method is different from WebElement.sendKeys(CharSequence…) – see sendKeys(CharSequence…) for details how.

dsdsd

Leave a Reply

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