1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- from typing import TYPE_CHECKING , List , Optional , Tuple , cast
15+ from typing import TYPE_CHECKING , List , Optional , Self , Tuple , cast
1616
1717from selenium .webdriver .common .action_chains import ActionChains
1818from selenium .webdriver .common .actions import interaction
2323from appium .webdriver .webelement import WebElement
2424
2525if TYPE_CHECKING :
26+ # noinspection PyUnresolvedReferences
2627 from appium .webdriver .webdriver import WebDriver
2728
2829
2930class ActionHelpers :
30- def scroll (self , origin_el : WebElement , destination_el : WebElement , duration : Optional [int ] = None ) -> 'WebDriver' :
31+ def scroll (self , origin_el : WebElement , destination_el : WebElement , duration : Optional [int ] = None ) -> Self :
3132 """Scrolls from one element to another
3233
3334 Args:
@@ -48,7 +49,7 @@ def scroll(self, origin_el: WebElement, destination_el: WebElement, duration: Op
4849
4950 touch_input = PointerInput (interaction .POINTER_TOUCH , 'touch' )
5051
51- actions = ActionChains (self )
52+ actions = ActionChains (cast ( 'WebDriver' , self ) )
5253 actions .w3c_actions = ActionBuilder (self , mouse = touch_input )
5354
5455 # https://github.com/SeleniumHQ/selenium/blob/3c82c868d4f2a7600223a1b3817301d0b04d28e4/py/selenium/webdriver/common/actions/pointer_actions.py#L83
@@ -59,11 +60,9 @@ def scroll(self, origin_el: WebElement, destination_el: WebElement, duration: Op
5960 actions .w3c_actions .pointer_action .move_to (destination_el )
6061 actions .w3c_actions .pointer_action .release ()
6162 actions .perform ()
62- return cast ( 'WebDriver' , self )
63+ return self
6364
64- def drag_and_drop (
65- self , origin_el : WebElement , destination_el : WebElement , pause : Optional [float ] = None
66- ) -> 'WebDriver' :
65+ def drag_and_drop (self , origin_el : WebElement , destination_el : WebElement , pause : Optional [float ] = None ) -> Self :
6766 """Drag the origin element to the destination element
6867
6968 Args:
@@ -74,17 +73,17 @@ def drag_and_drop(
7473 Returns:
7574 Union['WebDriver', 'ActionHelpers']: Self instance
7675 """
77- actions = ActionChains (self )
76+ actions = ActionChains (cast ( 'WebDriver' , self ) )
7877 # 'mouse' pointer action
7978 actions .w3c_actions .pointer_action .click_and_hold (origin_el )
8079 if pause is not None and pause > 0 :
8180 actions .w3c_actions .pointer_action .pause (pause )
8281 actions .w3c_actions .pointer_action .move_to (destination_el )
8382 actions .w3c_actions .pointer_action .release ()
8483 actions .perform ()
85- return cast ( 'WebDriver' , self )
84+ return self
8685
87- def tap (self , positions : List [Tuple [int , int ]], duration : Optional [int ] = None ) -> 'WebDriver' :
86+ def tap (self , positions : List [Tuple [int , int ]], duration : Optional [int ] = None ) -> Self :
8887 """Taps on an particular place with up to five fingers, holding for a
8988 certain time
9089
@@ -100,7 +99,7 @@ def tap(self, positions: List[Tuple[int, int]], duration: Optional[int] = None)
10099 Union['WebDriver', 'ActionHelpers']: Self instance
101100 """
102101 if len (positions ) == 1 :
103- actions = ActionChains (self )
102+ actions = ActionChains (cast ( 'WebDriver' , self ) )
104103 actions .w3c_actions = ActionBuilder (self , mouse = PointerInput (interaction .POINTER_TOUCH , 'touch' ))
105104 x = positions [0 ][0 ]
106105 y = positions [0 ][1 ]
@@ -114,7 +113,7 @@ def tap(self, positions: List[Tuple[int, int]], duration: Optional[int] = None)
114113 actions .perform ()
115114 else :
116115 finger = 0
117- actions = ActionChains (self )
116+ actions = ActionChains (cast ( 'WebDriver' , self ) )
118117 actions .w3c_actions .devices = []
119118
120119 for position in positions :
@@ -132,9 +131,9 @@ def tap(self, positions: List[Tuple[int, int]], duration: Optional[int] = None)
132131 new_input .create_pause (0.1 )
133132 new_input .create_pointer_up (MouseButton .LEFT )
134133 actions .perform ()
135- return cast ( 'WebDriver' , self )
134+ return self
136135
137- def swipe (self , start_x : int , start_y : int , end_x : int , end_y : int , duration : int = 0 ) -> 'WebDriver' :
136+ def swipe (self , start_x : int , start_y : int , end_x : int , end_y : int , duration : int = 0 ) -> Self :
138137 """Swipe from one point to another point, for an optional duration.
139138
140139 Args:
@@ -152,7 +151,7 @@ def swipe(self, start_x: int, start_y: int, end_x: int, end_y: int, duration: in
152151 """
153152 touch_input = PointerInput (interaction .POINTER_TOUCH , 'touch' )
154153
155- actions = ActionChains (self )
154+ actions = ActionChains (cast ( 'WebDriver' , self ) )
156155 actions .w3c_actions = ActionBuilder (self , mouse = touch_input )
157156 actions .w3c_actions .pointer_action .move_to_location (start_x , start_y )
158157 actions .w3c_actions .pointer_action .pointer_down ()
@@ -161,9 +160,9 @@ def swipe(self, start_x: int, start_y: int, end_x: int, end_y: int, duration: in
161160 actions .w3c_actions .pointer_action .move_to_location (end_x , end_y )
162161 actions .w3c_actions .pointer_action .release ()
163162 actions .perform ()
164- return cast ( 'WebDriver' , self )
163+ return self
165164
166- def flick (self , start_x : int , start_y : int , end_x : int , end_y : int ) -> 'WebDriver' :
165+ def flick (self , start_x : int , start_y : int , end_x : int , end_y : int ) -> Self :
167166 """Flick from one point to another point.
168167
169168 Args:
@@ -178,11 +177,11 @@ def flick(self, start_x: int, start_y: int, end_x: int, end_y: int) -> 'WebDrive
178177 Returns:
179178 Union['WebDriver', 'ActionHelpers']: Self instance
180179 """
181- actions = ActionChains (self )
180+ actions = ActionChains (cast ( 'WebDriver' , self ) )
182181 actions .w3c_actions = ActionBuilder (self , mouse = PointerInput (interaction .POINTER_TOUCH , 'touch' ))
183182 actions .w3c_actions .pointer_action .move_to_location (start_x , start_y )
184183 actions .w3c_actions .pointer_action .pointer_down ()
185184 actions .w3c_actions .pointer_action .move_to_location (end_x , end_y )
186185 actions .w3c_actions .pointer_action .release ()
187186 actions .perform ()
188- return cast ( 'WebDriver' , self )
187+ return self
0 commit comments