Debian Codegraph @

selenium/webdriver/common/actions/wheel_input.py

raw symbols SCIP
1 # Licensed to the Software Freedom Conservancy (SFC) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The SFC licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17 from typing import Union
18
19 from selenium.webdriver.remote.webelement import WebElement
20
21 from . import interaction
22 from .input_device import InputDevice
23
24
25 class ScrollOrigin:
26 def __init__(self, origin: Union[str, WebElement], x_offset: int, y_offset: int) -> None:
27 self._origin = origin
28 self._x_offset = x_offset
29 self._y_offset = y_offset
30
31 @classmethod
32 def from_element(cls, element: WebElement, x_offset: int = 0, y_offset: int = 0):
33 return cls(element, x_offset, y_offset)
34
35 @classmethod
36 def from_viewport(cls, x_offset: int = 0, y_offset: int = 0):
37 return cls("viewport", x_offset, y_offset)
38
39 @property
40 def origin(self) -> Union[str, WebElement]:
41 return self._origin
42
43 @property
44 def x_offset(self) -> int:
45 return self._x_offset
46
47 @property
48 def y_offset(self) -> int:
49 return self._y_offset
50
51
52 class WheelInput(InputDevice):
53 def __init__(self, name) -> None:
54 super().__init__(name=name)
55 self.name = name
56 self.type = interaction.WHEEL
57
58 def encode(self) -> dict:
59 return {"type": self.type, "id": self.name, "actions": self.actions}
60
61 def create_scroll(self, x: int, y: int, delta_x: int, delta_y: int, duration: int, origin) -> None:
62 if isinstance(origin, WebElement):
63 origin = {"element-6066-11e4-a52e-4f735466cecf": origin.id}
64 self.add_action(
65 {
66 "type": "scroll",
67 "x": x,
68 "y": y,
69 "deltaX": delta_x,
70 "deltaY": delta_y,
71 "duration": duration,
72 "origin": origin,
73 }
74 )
75
76 def create_pause(self, pause_duration: float) -> None:
77 self.add_action({"type": "pause", "duration": int(pause_duration * 1000)})