19
19
from selenium .webdriver .common .actions .action_builder import ActionBuilder
20
20
from selenium .webdriver .common .actions .mouse_button import MouseButton
21
21
from selenium .webdriver .common .actions .pointer_input import PointerInput
22
+ from typing_extensions import Self
22
23
23
24
from appium .webdriver .webelement import WebElement
24
25
25
26
if TYPE_CHECKING :
27
+ # noinspection PyUnresolvedReferences
26
28
from appium .webdriver .webdriver import WebDriver
27
29
28
30
29
31
class ActionHelpers :
30
- def scroll (self , origin_el : WebElement , destination_el : WebElement , duration : Optional [int ] = None ) -> 'WebDriver' :
32
+ def scroll (self , origin_el : WebElement , destination_el : WebElement , duration : Optional [int ] = None ) -> Self :
31
33
"""Scrolls from one element to another
32
34
33
35
Args:
@@ -48,7 +50,7 @@ def scroll(self, origin_el: WebElement, destination_el: WebElement, duration: Op
48
50
49
51
touch_input = PointerInput (interaction .POINTER_TOUCH , 'touch' )
50
52
51
- actions = ActionChains (self )
53
+ actions = ActionChains (cast ( 'WebDriver' , self ) )
52
54
actions .w3c_actions = ActionBuilder (self , mouse = touch_input )
53
55
54
56
# https://github.com/SeleniumHQ/selenium/blob/3c82c868d4f2a7600223a1b3817301d0b04d28e4/py/selenium/webdriver/common/actions/pointer_actions.py#L83
@@ -59,11 +61,9 @@ def scroll(self, origin_el: WebElement, destination_el: WebElement, duration: Op
59
61
actions .w3c_actions .pointer_action .move_to (destination_el )
60
62
actions .w3c_actions .pointer_action .release ()
61
63
actions .perform ()
62
- return cast ( 'WebDriver' , self )
64
+ return self
63
65
64
- def drag_and_drop (
65
- self , origin_el : WebElement , destination_el : WebElement , pause : Optional [float ] = None
66
- ) -> 'WebDriver' :
66
+ def drag_and_drop (self , origin_el : WebElement , destination_el : WebElement , pause : Optional [float ] = None ) -> Self :
67
67
"""Drag the origin element to the destination element
68
68
69
69
Args:
@@ -74,17 +74,17 @@ def drag_and_drop(
74
74
Returns:
75
75
Union['WebDriver', 'ActionHelpers']: Self instance
76
76
"""
77
- actions = ActionChains (self )
77
+ actions = ActionChains (cast ( 'WebDriver' , self ) )
78
78
# 'mouse' pointer action
79
79
actions .w3c_actions .pointer_action .click_and_hold (origin_el )
80
80
if pause is not None and pause > 0 :
81
81
actions .w3c_actions .pointer_action .pause (pause )
82
82
actions .w3c_actions .pointer_action .move_to (destination_el )
83
83
actions .w3c_actions .pointer_action .release ()
84
84
actions .perform ()
85
- return cast ( 'WebDriver' , self )
85
+ return self
86
86
87
- def tap (self , positions : List [Tuple [int , int ]], duration : Optional [int ] = None ) -> 'WebDriver' :
87
+ def tap (self , positions : List [Tuple [int , int ]], duration : Optional [int ] = None ) -> Self :
88
88
"""Taps on an particular place with up to five fingers, holding for a
89
89
certain time
90
90
@@ -100,7 +100,7 @@ def tap(self, positions: List[Tuple[int, int]], duration: Optional[int] = None)
100
100
Union['WebDriver', 'ActionHelpers']: Self instance
101
101
"""
102
102
if len (positions ) == 1 :
103
- actions = ActionChains (self )
103
+ actions = ActionChains (cast ( 'WebDriver' , self ) )
104
104
actions .w3c_actions = ActionBuilder (self , mouse = PointerInput (interaction .POINTER_TOUCH , 'touch' ))
105
105
x = positions [0 ][0 ]
106
106
y = positions [0 ][1 ]
@@ -114,7 +114,7 @@ def tap(self, positions: List[Tuple[int, int]], duration: Optional[int] = None)
114
114
actions .perform ()
115
115
else :
116
116
finger = 0
117
- actions = ActionChains (self )
117
+ actions = ActionChains (cast ( 'WebDriver' , self ) )
118
118
actions .w3c_actions .devices = []
119
119
120
120
for position in positions :
@@ -132,9 +132,9 @@ def tap(self, positions: List[Tuple[int, int]], duration: Optional[int] = None)
132
132
new_input .create_pause (0.1 )
133
133
new_input .create_pointer_up (MouseButton .LEFT )
134
134
actions .perform ()
135
- return cast ( 'WebDriver' , self )
135
+ return self
136
136
137
- def swipe (self , start_x : int , start_y : int , end_x : int , end_y : int , duration : int = 0 ) -> 'WebDriver' :
137
+ def swipe (self , start_x : int , start_y : int , end_x : int , end_y : int , duration : int = 0 ) -> Self :
138
138
"""Swipe from one point to another point, for an optional duration.
139
139
140
140
Args:
@@ -152,7 +152,7 @@ def swipe(self, start_x: int, start_y: int, end_x: int, end_y: int, duration: in
152
152
"""
153
153
touch_input = PointerInput (interaction .POINTER_TOUCH , 'touch' )
154
154
155
- actions = ActionChains (self )
155
+ actions = ActionChains (cast ( 'WebDriver' , self ) )
156
156
actions .w3c_actions = ActionBuilder (self , mouse = touch_input )
157
157
actions .w3c_actions .pointer_action .move_to_location (start_x , start_y )
158
158
actions .w3c_actions .pointer_action .pointer_down ()
@@ -161,9 +161,9 @@ def swipe(self, start_x: int, start_y: int, end_x: int, end_y: int, duration: in
161
161
actions .w3c_actions .pointer_action .move_to_location (end_x , end_y )
162
162
actions .w3c_actions .pointer_action .release ()
163
163
actions .perform ()
164
- return cast ( 'WebDriver' , self )
164
+ return self
165
165
166
- def flick (self , start_x : int , start_y : int , end_x : int , end_y : int ) -> 'WebDriver' :
166
+ def flick (self , start_x : int , start_y : int , end_x : int , end_y : int ) -> Self :
167
167
"""Flick from one point to another point.
168
168
169
169
Args:
@@ -178,11 +178,11 @@ def flick(self, start_x: int, start_y: int, end_x: int, end_y: int) -> 'WebDrive
178
178
Returns:
179
179
Union['WebDriver', 'ActionHelpers']: Self instance
180
180
"""
181
- actions = ActionChains (self )
181
+ actions = ActionChains (cast ( 'WebDriver' , self ) )
182
182
actions .w3c_actions = ActionBuilder (self , mouse = PointerInput (interaction .POINTER_TOUCH , 'touch' ))
183
183
actions .w3c_actions .pointer_action .move_to_location (start_x , start_y )
184
184
actions .w3c_actions .pointer_action .pointer_down ()
185
185
actions .w3c_actions .pointer_action .move_to_location (end_x , end_y )
186
186
actions .w3c_actions .pointer_action .release ()
187
187
actions .perform ()
188
- return cast ( 'WebDriver' , self )
188
+ return self
0 commit comments