Reputation: 510
I want to click on a picture that is inside a canvas container, then without release the click I drag the mouse to other point, and this whole operation should mark some part of the picture.
Manually is it working.
What I've tried to do with Selenium is:
public static void func(WebDriver driver, WebElement canvasImageContainer,
int startX, int startY, int endX, int endY) throws Exception {
validateCoord(imageContainer.getSize(), startX, startY, endX, endY); //just validates the coordinates are not negative, not bigger than image size, etc
int xOffset = endX - startX;
int yOffset = endY - startY;
Actions actions = new Actions(driver);
actions.moveToElement(imageContainer, startX, startY)
.clickAndHold()
.moveByOffset(xOffset, yOffset)
.release()
.perform();
}
But it is not working, nothing happend, am I using it wrong?
Thanks
Upvotes: 0
Views: 718
Reputation: 2799
We use build() when we are performing sequence of operations and no need to use if we are performing single action. In the above code you are performing more than one operations. So, you need to use build() to compile all the actions into a single step.
Use code snippet as follows:
actions.moveToElement(imageContainer, startX, startY)
.clickAndHold()
.moveByOffset(xOffset, yOffset)
.release()
.build()
.perform();
Upvotes: 1