- Learn Selenium
- Unmesh Gundecha Carl Cocchiaro
- 150字
- 2021-06-24 13:25:44
The release at current location action
Now, in the previous example, we have seen how to click and hold an element. The ultimate action that has to be taken on a held WebElement is to release it so that the element can be dropped or released from the mouse. The release() method is the one that can release the left mouse button on a WebElement.
The API syntax for the release() method is as follows: public Actions release().
The preceding method doesn't take any input parameter and returns the Actions class instance.
Now, let's modify the previous code to include the release action in it:
@Test
public void shouldClickAndHoldAndRelease() {
driver.get("http://guidebook.seleniumacademy.com/Sortable.html");
WebElement three = driver.findElement(By.name("three"));
Actions actions = new Actions(driver);
//Move tile3 to the position of tile2
actions.clickAndHold(three)
.moveByOffset(120, 0)
.release()
.perform();
}
The preceding code will make sure that the mouse is released at the specified location.