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

Method perform

java/src/org/openqa/selenium/bidi/module/Input.java:43–89  ·  view source on GitHub ↗
(String browsingContext, Collection<Sequence> actions)

Source from the content-addressed store, hash-verified

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) {
92 bidi.send(new Command<>("input.releaseActions", Map.of("context", browsingContext)));

Callers

nothing calls this directly

Calls 12

filterMethod · 0.80
getMethod · 0.65
getClassMethod · 0.65
putMethod · 0.65
sendMethod · 0.65
mapMethod · 0.45
streamMethod · 0.45
forEachMethod · 0.45
equalsMethod · 0.45
invokeMethod · 0.45
getMethodMethod · 0.45
ofMethod · 0.45

Tested by

no test coverage detected