|
Answer» Selenium has the ability to handle various types of keyboard and MOUSE events. In order to perform action events, use org.openqa.selenium.interactions Actions in CLASS. This API includes actions such as clicking multiple elements, drag and drop. Let us create an object action of Action class. - Actions action = new Actions(driver);
Now to focus on an element using WebDriver use action - - actions.moveToElement(element).perform();
Here perform() method is used to execute the action. Let us see mouse events using selenium action class API - - click() : It Clicks on an element.
- doubleClick() : Double clicks onElement.
- contextClick() : Performs a context-click on an element.
- clickAndHold() : It Clicks on an element without releasing.
- dragAndDrop(source, target) : Invokes click-and-hold at the LOCATION and moves to the target location of the element before releasing the mouse. where the source is an element to grab and the target is the element to release.
- dragAndDropBy(source, XOFFSET, yOffset) : Performs click-and-hold at the source location and shifts by a GIVEN offset, then frees the mouse. Here xOffset is to shift horizontally and yOffset is to shift vertically.
- moveByOffset(x-offset, y-offset) : Shifts the mouse from its current position (or 0,0) by the given offset.
- moveToElement(toElement) : Shifts the mouse to the centre of the element.
- release() : Releases left mouse button at the existing mouse location
|