val clickable = driver.findElement(By.id("clickable"))Actions(driver).moveToElement(clickable).pause(Duration.ofSeconds(1)).clickAndHold().pause(Duration.ofSeconds(1)).sendKeys("abc").perform()
val mouse =PointerInput(PointerInput.Kind.MOUSE,"default mouse")val actions =Sequence(mouse,0).addAction(mouse.createPointerDown(PointerInput.MouseButton.BACK.asArg())).addAction(mouse.createPointerUp(PointerInput.MouseButton.BACK.asArg()))(driver as RemoteWebDriver).perform(Collections.singletonList(actions))
val mouse =PointerInput(PointerInput.Kind.MOUSE,"default mouse")val actions =Sequence(mouse,0).addAction(mouse.createPointerDown(PointerInput.MouseButton.FORWARD.asArg())).addAction(mouse.createPointerUp(PointerInput.MouseButton.FORWARD.asArg()))(driver as RemoteWebDriver).perform(Collections.singletonList(actions))
val mouse =PointerInput(PointerInput.Kind.MOUSE,"default mouse")val actions =Sequence(mouse,0).addAction(mouse.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(),8,12))(driver as RemoteWebDriver).perform(Collections.singletonList(actions))
A Pen is a type of pointer input that has most of the same behavior as a mouse, but can
also have event properties unique to a stylus. Additionally, while a mouse
has 5 buttons, a pen has 3 equivalent button states:
0 — Touch Contact (the default; equivalent to a left click)
2 — Barrel Button (equivalent to a right click)
5 — Eraser Button (currently unsupported by drivers)
val pointerArea = driver.findElement(By.id("pointerArea"))Actions(driver).setActivePointer(PointerInput.Kind.PEN,"default pen").moveToElement(pointerArea).clickAndHold().moveByOffset(2,2).release().perform()
This is the most common scenario. Unlike traditional click and send keys methods,
the actions class does not automatically scroll the target element into view,
so this method will need to be used if elements are not already inside the viewport.
This method takes a web element as the sole argument.
Regardless of whether the element is above or below the current viewscreen,
the viewport will be scrolled so the bottom of the element is at the bottom of the screen.
This is the second most common scenario for scrolling. Pass in an delta x and a delta y value for how much to scroll
in the right and down directions. Negative values represent left and up, respectively.
This scenario is effectively a combination of the above two methods.
To execute this use the “Scroll From” method, which takes 3 arguments.
The first represents the origination point, which we designate as the element,
and the second two are the delta x and delta y values.
If the element is out of the viewport,
it will be scrolled to the bottom of the screen, then the page will be scrolled by the provided
delta x and delta y values.
This scenario is used when you need to scroll only a portion of the screen, and it is outside the viewport.
Or is inside the viewport and the portion of the screen that must be scrolled
is a known offset away from a specific element.
This uses the “Scroll From” method again, and in addition to specifying the element,
an offset is specified to indicate the origin point of the scroll. The offset is
calculated from the center of the provided element.
If the element is out of the viewport,
it first will be scrolled to the bottom of the screen, then the origin of the scroll will be determined
by adding the offset to the coordinates of the center of the element, and finally
the page will be scrolled by the provided delta x and delta y values.
Note that if the offset from the center of the element falls outside of the viewport,
it will result in an exception.
Scroll from a offset of origin (element) by given amount
The final scenario is used when you need to scroll only a portion of the screen,
and it is already inside the viewport.
This uses the “Scroll From” method again, but the viewport is designated instead
of an element. An offset is specified from the upper left corner of the
current viewport. After the origin point is determined,
the page will be scrolled by the provided delta x and delta y values.
Note that if the offset from the upper left corner of the viewport falls outside of the screen,
it will result in an exception.