Skip to content

Commit a7ba9ef

Browse files
modified the interaction class to have InputDevice, and based on it corrected other files
1 parent fdcd615 commit a7ba9ef

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

py/selenium/webdriver/common/actions/interaction.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
# under the License.
1717
from typing import Union
1818

19+
from .input_device import InputDevice
20+
1921
KEY = "key"
2022
POINTER = "pointer"
2123
NONE = "none"
2224
WHEEL = "wheel"
23-
SOURCE_TYPES = {KEY, POINTER, NONE}
25+
SOURCE_TYPES = {KEY, POINTER, WHEEL, NONE}
2426

2527
POINTER_MOUSE = "mouse"
2628
POINTER_TOUCH = "touch"
@@ -32,7 +34,7 @@
3234
class Interaction:
3335
PAUSE = "pause"
3436

35-
def __init__(self, source: str) -> None:
37+
def __init__(self, source: InputDevice) -> None:
3638
self.source = source
3739

3840

py/selenium/webdriver/common/actions/key_actions.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from __future__ import annotations
1919

2020
from ..utils import keys_to_typing
21-
from .interaction import KEY, POINTER, WHEEL, Interaction
21+
from .interaction import KEY, Interaction
2222
from .key_input import KeyInput
2323
from .pointer_input import PointerInput
2424
from .wheel_input import WheelInput
@@ -28,19 +28,7 @@ class KeyActions(Interaction):
2828
def __init__(self, source: KeyInput | PointerInput | WheelInput | None = None) -> None:
2929
if source is None:
3030
source = KeyInput(KEY)
31-
self.input_source = source
32-
33-
# Determine the correct source type string based on the input object
34-
if isinstance(source, KeyInput):
35-
source_type = KEY
36-
elif isinstance(source, PointerInput):
37-
source_type = POINTER
38-
elif isinstance(source, WheelInput):
39-
source_type = WHEEL
40-
else:
41-
source_type = KEY
42-
43-
super().__init__(source_type)
31+
super().__init__(source)
4432

4533
def key_down(self, letter: str) -> KeyActions:
4634
return self._key_action("create_key_down", letter)
@@ -60,6 +48,6 @@ def send_keys(self, text: str | list) -> KeyActions:
6048
return self
6149

6250
def _key_action(self, action: str, letter) -> KeyActions:
63-
meth = getattr(self.input_source, action)
51+
meth = getattr(self.source, action)
6452
meth(letter)
6553
return self

py/selenium/webdriver/common/actions/wheel_actions.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,20 @@
1717

1818
from typing import Optional
1919

20-
from .interaction import Interaction
20+
from .interaction import WHEEL, Interaction
2121
from .wheel_input import WheelInput
2222

2323

2424
class WheelActions(Interaction):
2525
def __init__(self, source: Optional[WheelInput] = None):
2626
if source is None:
27-
source = WheelInput("wheel")
28-
super().__init__(source.type)
29-
self._source = source
27+
source = WheelInput(WHEEL)
28+
super().__init__(source)
3029

3130
def pause(self, duration: float = 0):
32-
self._source.create_pause(duration)
31+
self.source.create_pause(duration)
3332
return self
3433

3534
def scroll(self, x=0, y=0, delta_x=0, delta_y=0, duration=0, origin="viewport"):
36-
self._source.create_scroll(x, y, delta_x, delta_y, duration, origin)
35+
self.source.create_scroll(x, y, delta_x, delta_y, duration, origin)
3736
return self

0 commit comments

Comments
 (0)