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

Method perform

java/src/org/openqa/selenium/bidi/module/Input.java:43–84  ·  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(encodedAction -> {
51 String type = (String) encodedAction.get("type");
52 // Element as origin is only possible for input pointer or wheel
53 if (type.equals("pointer") || type.equals("wheel")) {
54 List<Map<String, Object>> actionList =
55 (List<Map<String, Object>>) encodedAction.get("actions");
56
57 actionList.stream()
58 .filter(action ->
59 // For pointer only pointMove action can have element as origin
60 action.get("type").equals("pointerMove") || action.get("type").equals("scroll"))
61 .filter(action -> action.get("origin") instanceof WebElement)
62 .forEach(action -> {
63 Object element = action.get("origin");
64 try {
65 // Using reflection because adding RemoteWebElement as a dependency creates
66 // a circular dependency in Bazel
67 String id = (String) element.getClass().getMethod("getId").invoke(element);
68 // sharedId is required by BiDi, the reason for this step
69 action.put("origin", Map.of("type", "element", "element", Map.of("sharedId", id)));
70 } catch (NoSuchMethodException
71 | InvocationTargetException
72 | IllegalAccessException e) {
73 throw new RuntimeException(e);
74 }
75 });
76 }
77 });
78 bidi.send(
79 new Command<>(
80 "input.performActions",
81 Map.of(
82 "context", browsingContext,
83 "actions", encodedActions)));
84 }
85
86 public void release(String browsingContext) {
87 bidi.send(new Command<>("input.releaseActions", Map.of("context", browsingContext)));

Callers

nothing calls this directly

Calls 13

collectMethod · 0.80
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

Tested by

no test coverage detected