1919from selenium .webdriver .common .actions .action_builder import ActionBuilder
2020from selenium .webdriver .common .actions .mouse_button import MouseButton
2121from selenium .webdriver .common .actions .pointer_input import PointerInput
22+ from typing_extensions import Self
2223
2324from appium .webdriver .webelement import WebElement
2425
2526if TYPE_CHECKING :
27+ # noinspection PyUnresolvedReferences
2628 from appium .webdriver .webdriver import WebDriver
2729
2830
2931class 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 :
3133 """Scrolls from one element to another
3234
3335 Args:
@@ -48,7 +50,7 @@ def scroll(self, origin_el: WebElement, destination_el: WebElement, duration: Op
4850
4951 touch_input = PointerInput (interaction .POINTER_TOUCH , 'touch' )
5052
51- actions = ActionChains (self )
53+ actions = ActionChains (cast ( 'WebDriver' , self ) )
5254 actions .w3c_actions = ActionBuilder (self , mouse = touch_input )
5355
5456 # 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
5961 actions .w3c_actions .pointer_action .move_to (destination_el )
6062 actions .w3c_actions .pointer_action .release ()
6163 actions .perform ()
62- return cast ( 'WebDriver' , self )
64+ return self
6365
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 :
6767 """Drag the origin element to the destination element
6868
6969 Args:
@@ -74,17 +74,17 @@ def drag_and_drop(
7474 Returns:
7575 Union['WebDriver', 'ActionHelpers']: Self instance
7676 """
77- actions = ActionChains (self )
77+ actions = ActionChains (cast ( 'WebDriver' , self ) )
7878 # 'mouse' pointer action
7979 actions .w3c_actions .pointer_action .click_and_hold (origin_el )
8080 if pause is not None and pause > 0 :
8181 actions .w3c_actions .pointer_action .pause (pause )
8282 actions .w3c_actions .pointer_action .move_to (destination_el )
8383 actions .w3c_actions .pointer_action .release ()
8484 actions .perform ()
85- return cast ( 'WebDriver' , self )
85+ return self
8686
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 :
8888 """Taps on an particular place with up to five fingers, holding for a
8989 certain time
9090
@@ -100,7 +100,7 @@ def tap(self, positions: List[Tuple[int, int]], duration: Optional[int] = None)
100100 Union['WebDriver', 'ActionHelpers']: Self instance
101101 """
102102 if len (positions ) == 1 :
103- actions = ActionChains (self )
103+ actions = ActionChains (cast ( 'WebDriver' , self ) )
104104 actions .w3c_actions = ActionBuilder (self , mouse = PointerInput (interaction .POINTER_TOUCH , 'touch' ))
105105 x = positions [0 ][0 ]
106106 y = positions [0 ][1 ]
@@ -114,7 +114,7 @@ def tap(self, positions: List[Tuple[int, int]], duration: Optional[int] = None)
114114 actions .perform ()
115115 else :
116116 finger = 0
117- actions = ActionChains (self )
117+ actions = ActionChains (cast ( 'WebDriver' , self ) )
118118 actions .w3c_actions .devices = []
119119
120120 for position in positions :
@@ -132,9 +132,9 @@ def tap(self, positions: List[Tuple[int, int]], duration: Optional[int] = None)
132132 new_input .create_pause (0.1 )
133133 new_input .create_pointer_up (MouseButton .LEFT )
134134 actions .perform ()
135- return cast ( 'WebDriver' , self )
135+ return self
136136
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 :
138138 """Swipe from one point to another point, for an optional duration.
139139
140140 Args:
@@ -152,7 +152,7 @@ def swipe(self, start_x: int, start_y: int, end_x: int, end_y: int, duration: in
152152 """
153153 touch_input = PointerInput (interaction .POINTER_TOUCH , 'touch' )
154154
155- actions = ActionChains (self )
155+ actions = ActionChains (cast ( 'WebDriver' , self ) )
156156 actions .w3c_actions = ActionBuilder (self , mouse = touch_input )
157157 actions .w3c_actions .pointer_action .move_to_location (start_x , start_y )
158158 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
161161 actions .w3c_actions .pointer_action .move_to_location (end_x , end_y )
162162 actions .w3c_actions .pointer_action .release ()
163163 actions .perform ()
164- return cast ( 'WebDriver' , self )
164+ return self
165165
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 :
167167 """Flick from one point to another point.
168168
169169 Args:
@@ -178,11 +178,11 @@ def flick(self, start_x: int, start_y: int, end_x: int, end_y: int) -> 'WebDrive
178178 Returns:
179179 Union['WebDriver', 'ActionHelpers']: Self instance
180180 """
181- actions = ActionChains (self )
181+ actions = ActionChains (cast ( 'WebDriver' , self ) )
182182 actions .w3c_actions = ActionBuilder (self , mouse = PointerInput (interaction .POINTER_TOUCH , 'touch' ))
183183 actions .w3c_actions .pointer_action .move_to_location (start_x , start_y )
184184 actions .w3c_actions .pointer_action .pointer_down ()
185185 actions .w3c_actions .pointer_action .move_to_location (end_x , end_y )
186186 actions .w3c_actions .pointer_action .release ()
187187 actions .perform ()
188- return cast ( 'WebDriver' , self )
188+ return self
0 commit comments