Reputation: 613
I am interested in mechanism of WebDriver actions. For example
var actions = new Actions(driver);
var action = actions.MoveToElement(element).Build();
action.Perform();
How method MoveToElement() works? Is it a wrapper on javascript? If yes, is it possible to get this javascript code?
Upvotes: 1
Views: 1432
Reputation: 591
moveToElement is implemented based on coordinates. following is the code for moveToElement is the following
public Actions moveToElement(WebElement toElement) {
this.action.addAction(new MoveMouseAction(this.mouse,
(Locatable) toElement));
return this;
}
public abstract interface Locatable {
public abstract Coordinates getCoordinates();
}
public class MoveMouseAction extends MouseAction implements Action {
public MoveMouseAction(Mouse mouse, Locatable locationProvider) {
super(mouse, locationProvider);
if (locationProvider == null)
throw new IllegalArgumentException(
"Must provide a location for a move action.");
}
public void perform() {
this.mouse.mouseMove(getActionLocation());
}
}
Upvotes: 1
Reputation: 5072
No javascript. It uses coordinates to move mouse there. Check this link.
Upvotes: 0
Reputation: 29032
So - I was actually curious about the mechanics myself, so I took a look through the selenium source, and my determination is that - no. It does not use javascript. It uses Java's ability to read / move the mouse positions / keyboard drivers / etc, and then when you call perform()
, it has a queue of Actions
that it will then perform.
Upvotes: 1