org.openqa.selenium.devtools.v85.input.Input Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of selenium-devtools-v85 Show documentation
Show all versions of selenium-devtools-v85 Show documentation
Selenium automates browsers. That's it! What you do with that power is entirely up to you.
package org.openqa.selenium.devtools.v85.input;
import org.openqa.selenium.Beta;
import org.openqa.selenium.devtools.Command;
import org.openqa.selenium.devtools.Event;
import org.openqa.selenium.devtools.ConverterFunctions;
import java.util.Map;
import java.util.LinkedHashMap;
import org.openqa.selenium.json.JsonInput;
public class Input {
public enum DispatchKeyEventType {
KEYDOWN("keyDown"), KEYUP("keyUp"), RAWKEYDOWN("rawKeyDown"), CHAR("char");
private String value;
DispatchKeyEventType(String value) {
this.value = value;
}
public static DispatchKeyEventType fromString(String s) {
return java.util.Arrays.stream(DispatchKeyEventType.values()).filter(rs -> rs.value.equalsIgnoreCase(s)).findFirst().orElseThrow(() -> new org.openqa.selenium.devtools.DevToolsException("Given value " + s + " is not found within DispatchKeyEventType "));
}
public String toString() {
return value;
}
public String toJson() {
return value;
}
private static DispatchKeyEventType fromJson(JsonInput input) {
return fromString(input.nextString());
}
}
/**
* Dispatches a key event to the page.
*/
public static Command dispatchKeyEvent(DispatchKeyEventType type, java.util.Optional modifiers, java.util.Optional timestamp, java.util.Optional text, java.util.Optional unmodifiedText, java.util.Optional keyIdentifier, java.util.Optional code, java.util.Optional key, java.util.Optional windowsVirtualKeyCode, java.util.Optional nativeVirtualKeyCode, java.util.Optional autoRepeat, java.util.Optional isKeypad, java.util.Optional isSystemKey, java.util.Optional location, java.util.Optional> commands) {
java.util.Objects.requireNonNull(type, "type is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("type", type);
modifiers.ifPresent(p -> params.put("modifiers", p));
timestamp.ifPresent(p -> params.put("timestamp", p));
text.ifPresent(p -> params.put("text", p));
unmodifiedText.ifPresent(p -> params.put("unmodifiedText", p));
keyIdentifier.ifPresent(p -> params.put("keyIdentifier", p));
code.ifPresent(p -> params.put("code", p));
key.ifPresent(p -> params.put("key", p));
windowsVirtualKeyCode.ifPresent(p -> params.put("windowsVirtualKeyCode", p));
nativeVirtualKeyCode.ifPresent(p -> params.put("nativeVirtualKeyCode", p));
autoRepeat.ifPresent(p -> params.put("autoRepeat", p));
isKeypad.ifPresent(p -> params.put("isKeypad", p));
isSystemKey.ifPresent(p -> params.put("isSystemKey", p));
location.ifPresent(p -> params.put("location", p));
commands.ifPresent(p -> params.put("commands", p));
return new Command<>("Input.dispatchKeyEvent", Map.copyOf(params));
}
/**
* This method emulates inserting text that doesn't come from a key press,
* for example an emoji keyboard or an IME.
*/
@Beta()
public static Command insertText(java.lang.String text) {
java.util.Objects.requireNonNull(text, "text is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("text", text);
return new Command<>("Input.insertText", Map.copyOf(params));
}
public enum DispatchMouseEventType {
MOUSEPRESSED("mousePressed"), MOUSERELEASED("mouseReleased"), MOUSEMOVED("mouseMoved"), MOUSEWHEEL("mouseWheel");
private String value;
DispatchMouseEventType(String value) {
this.value = value;
}
public static DispatchMouseEventType fromString(String s) {
return java.util.Arrays.stream(DispatchMouseEventType.values()).filter(rs -> rs.value.equalsIgnoreCase(s)).findFirst().orElseThrow(() -> new org.openqa.selenium.devtools.DevToolsException("Given value " + s + " is not found within DispatchMouseEventType "));
}
public String toString() {
return value;
}
public String toJson() {
return value;
}
private static DispatchMouseEventType fromJson(JsonInput input) {
return fromString(input.nextString());
}
}
public enum DispatchMouseEventPointerType {
MOUSE("mouse"), PEN("pen");
private String value;
DispatchMouseEventPointerType(String value) {
this.value = value;
}
public static DispatchMouseEventPointerType fromString(String s) {
return java.util.Arrays.stream(DispatchMouseEventPointerType.values()).filter(rs -> rs.value.equalsIgnoreCase(s)).findFirst().orElseThrow(() -> new org.openqa.selenium.devtools.DevToolsException("Given value " + s + " is not found within DispatchMouseEventPointerType "));
}
public String toString() {
return value;
}
public String toJson() {
return value;
}
private static DispatchMouseEventPointerType fromJson(JsonInput input) {
return fromString(input.nextString());
}
}
/**
* Dispatches a mouse event to the page.
*/
public static Command dispatchMouseEvent(DispatchMouseEventType type, java.lang.Number x, java.lang.Number y, java.util.Optional modifiers, java.util.Optional timestamp, java.util.Optional button, java.util.Optional buttons, java.util.Optional clickCount, java.util.Optional deltaX, java.util.Optional deltaY, java.util.Optional pointerType) {
java.util.Objects.requireNonNull(type, "type is required");
java.util.Objects.requireNonNull(x, "x is required");
java.util.Objects.requireNonNull(y, "y is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("type", type);
params.put("x", x);
params.put("y", y);
modifiers.ifPresent(p -> params.put("modifiers", p));
timestamp.ifPresent(p -> params.put("timestamp", p));
button.ifPresent(p -> params.put("button", p));
buttons.ifPresent(p -> params.put("buttons", p));
clickCount.ifPresent(p -> params.put("clickCount", p));
deltaX.ifPresent(p -> params.put("deltaX", p));
deltaY.ifPresent(p -> params.put("deltaY", p));
pointerType.ifPresent(p -> params.put("pointerType", p));
return new Command<>("Input.dispatchMouseEvent", Map.copyOf(params));
}
public enum DispatchTouchEventType {
TOUCHSTART("touchStart"), TOUCHEND("touchEnd"), TOUCHMOVE("touchMove"), TOUCHCANCEL("touchCancel");
private String value;
DispatchTouchEventType(String value) {
this.value = value;
}
public static DispatchTouchEventType fromString(String s) {
return java.util.Arrays.stream(DispatchTouchEventType.values()).filter(rs -> rs.value.equalsIgnoreCase(s)).findFirst().orElseThrow(() -> new org.openqa.selenium.devtools.DevToolsException("Given value " + s + " is not found within DispatchTouchEventType "));
}
public String toString() {
return value;
}
public String toJson() {
return value;
}
private static DispatchTouchEventType fromJson(JsonInput input) {
return fromString(input.nextString());
}
}
/**
* Dispatches a touch event to the page.
*/
public static Command dispatchTouchEvent(DispatchTouchEventType type, java.util.List touchPoints, java.util.Optional modifiers, java.util.Optional timestamp) {
java.util.Objects.requireNonNull(type, "type is required");
java.util.Objects.requireNonNull(touchPoints, "touchPoints is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("type", type);
params.put("touchPoints", touchPoints);
modifiers.ifPresent(p -> params.put("modifiers", p));
timestamp.ifPresent(p -> params.put("timestamp", p));
return new Command<>("Input.dispatchTouchEvent", Map.copyOf(params));
}
public enum EmulateTouchFromMouseEventType {
MOUSEPRESSED("mousePressed"), MOUSERELEASED("mouseReleased"), MOUSEMOVED("mouseMoved"), MOUSEWHEEL("mouseWheel");
private String value;
EmulateTouchFromMouseEventType(String value) {
this.value = value;
}
public static EmulateTouchFromMouseEventType fromString(String s) {
return java.util.Arrays.stream(EmulateTouchFromMouseEventType.values()).filter(rs -> rs.value.equalsIgnoreCase(s)).findFirst().orElseThrow(() -> new org.openqa.selenium.devtools.DevToolsException("Given value " + s + " is not found within EmulateTouchFromMouseEventType "));
}
public String toString() {
return value;
}
public String toJson() {
return value;
}
private static EmulateTouchFromMouseEventType fromJson(JsonInput input) {
return fromString(input.nextString());
}
}
/**
* Emulates touch event from the mouse event parameters.
*/
@Beta()
public static Command emulateTouchFromMouseEvent(EmulateTouchFromMouseEventType type, java.lang.Integer x, java.lang.Integer y, org.openqa.selenium.devtools.v85.input.model.MouseButton button, java.util.Optional timestamp, java.util.Optional deltaX, java.util.Optional deltaY, java.util.Optional modifiers, java.util.Optional clickCount) {
java.util.Objects.requireNonNull(type, "type is required");
java.util.Objects.requireNonNull(x, "x is required");
java.util.Objects.requireNonNull(y, "y is required");
java.util.Objects.requireNonNull(button, "button is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("type", type);
params.put("x", x);
params.put("y", y);
params.put("button", button);
timestamp.ifPresent(p -> params.put("timestamp", p));
deltaX.ifPresent(p -> params.put("deltaX", p));
deltaY.ifPresent(p -> params.put("deltaY", p));
modifiers.ifPresent(p -> params.put("modifiers", p));
clickCount.ifPresent(p -> params.put("clickCount", p));
return new Command<>("Input.emulateTouchFromMouseEvent", Map.copyOf(params));
}
/**
* Ignores input events (useful while auditing page).
*/
public static Command setIgnoreInputEvents(java.lang.Boolean ignore) {
java.util.Objects.requireNonNull(ignore, "ignore is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("ignore", ignore);
return new Command<>("Input.setIgnoreInputEvents", Map.copyOf(params));
}
/**
* Synthesizes a pinch gesture over a time period by issuing appropriate touch events.
*/
@Beta()
public static Command synthesizePinchGesture(java.lang.Number x, java.lang.Number y, java.lang.Number scaleFactor, java.util.Optional relativeSpeed, java.util.Optional gestureSourceType) {
java.util.Objects.requireNonNull(x, "x is required");
java.util.Objects.requireNonNull(y, "y is required");
java.util.Objects.requireNonNull(scaleFactor, "scaleFactor is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("x", x);
params.put("y", y);
params.put("scaleFactor", scaleFactor);
relativeSpeed.ifPresent(p -> params.put("relativeSpeed", p));
gestureSourceType.ifPresent(p -> params.put("gestureSourceType", p));
return new Command<>("Input.synthesizePinchGesture", Map.copyOf(params));
}
/**
* Synthesizes a scroll gesture over a time period by issuing appropriate touch events.
*/
@Beta()
public static Command synthesizeScrollGesture(java.lang.Number x, java.lang.Number y, java.util.Optional xDistance, java.util.Optional yDistance, java.util.Optional xOverscroll, java.util.Optional yOverscroll, java.util.Optional preventFling, java.util.Optional speed, java.util.Optional gestureSourceType, java.util.Optional repeatCount, java.util.Optional repeatDelayMs, java.util.Optional interactionMarkerName) {
java.util.Objects.requireNonNull(x, "x is required");
java.util.Objects.requireNonNull(y, "y is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("x", x);
params.put("y", y);
xDistance.ifPresent(p -> params.put("xDistance", p));
yDistance.ifPresent(p -> params.put("yDistance", p));
xOverscroll.ifPresent(p -> params.put("xOverscroll", p));
yOverscroll.ifPresent(p -> params.put("yOverscroll", p));
preventFling.ifPresent(p -> params.put("preventFling", p));
speed.ifPresent(p -> params.put("speed", p));
gestureSourceType.ifPresent(p -> params.put("gestureSourceType", p));
repeatCount.ifPresent(p -> params.put("repeatCount", p));
repeatDelayMs.ifPresent(p -> params.put("repeatDelayMs", p));
interactionMarkerName.ifPresent(p -> params.put("interactionMarkerName", p));
return new Command<>("Input.synthesizeScrollGesture", Map.copyOf(params));
}
/**
* Synthesizes a tap gesture over a time period by issuing appropriate touch events.
*/
@Beta()
public static Command synthesizeTapGesture(java.lang.Number x, java.lang.Number y, java.util.Optional duration, java.util.Optional tapCount, java.util.Optional gestureSourceType) {
java.util.Objects.requireNonNull(x, "x is required");
java.util.Objects.requireNonNull(y, "y is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("x", x);
params.put("y", y);
duration.ifPresent(p -> params.put("duration", p));
tapCount.ifPresent(p -> params.put("tapCount", p));
gestureSourceType.ifPresent(p -> params.put("gestureSourceType", p));
return new Command<>("Input.synthesizeTapGesture", Map.copyOf(params));
}
}