MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / Input

Class Input

java/src/org/openqa/selenium/bidi/module/Input.java:34–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32import org.openqa.selenium.interactions.Sequence;
33
34@Beta
35public class Input {
36 private final BiDi bidi;
37
38 public Input(WebDriver driver) {
39 this.bidi = ((HasBiDi) driver).getBiDi();
40 }
41
42 // This will make porting from W3C WebDriver classic to BiDi seamless for Actions
43 @SuppressWarnings("unchecked")
44 public void perform(String browsingContext, Collection<Sequence> actions) {
45
46 // This step is needed to map the origin if it's an element to the key expected by BiDi
47 List<Map<String, Object>> encodedActions =
48 actions.stream().map(Sequence::encode).collect(Collectors.toList());
49
50 encodedActions.forEach(
51 encodedAction -> {
52 String type = (String) encodedAction.get("type");
53 // Element as origin is only possible for input pointer or wheel
54 if (type.equals("pointer") || type.equals("wheel")) {
55 List<Map<String, Object>> actionList =
56 (List<Map<String, Object>>) encodedAction.get("actions");
57
58 actionList.stream()
59 .filter(
60 action ->
61 // For pointer only pointMove action can have element as origin
62 action.get("type").equals("pointerMove")
63 || action.get("type").equals("scroll"))
64 .filter(action -> action.get("origin") instanceof WebElement)
65 .forEach(
66 action -> {
67 Object element = action.get("origin");
68 try {
69 // Using reflection because adding RemoteWebElement as a dependency creates
70 // a circular dependency in Bazel
71 String id = (String) element.getClass().getMethod("getId").invoke(element);
72 // sharedId is required by BiDi, the reason for this step
73 action.put(
74 "origin", Map.of("type", "element", "element", Map.of("sharedId", id)));
75 } catch (NoSuchMethodException
76 | InvocationTargetException
77 | IllegalAccessException e) {
78 throw new RuntimeException(e);
79 }
80 });
81 }
82 });
83 bidi.send(
84 new Command<>(
85 "input.performActions",
86 Map.of(
87 "context", browsingContext,
88 "actions", encodedActions)));
89 }
90
91 public void release(String browsingContext) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected