zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
U
[±d›2ã@sNdZddlZddlmZddlmZddlmZddlm    Z    Gdd    „d    ƒZ
dS)
z The ActionChains implementation,éN)Ú
WebElementé)Ú ActionBuilder)Ú ScrollOrigin)Úkeys_to_typingc@s
eZdZdZd:dd„Zdd„Zdd„Zd;d
d „Zd<d d „Zd=dd„Z    d>dd„Z
dd„Z dd„Z d?dd„Z d@dd„Zdd„Zdd„Zdd„Zd d!„ZdAd"d#„Zd$d%„Zd&d'„Zed(œd)d*„Zeed+œd,d-„Zeeed.œd/d0„ZdBeeeeeed3œd4d5„Zd6d7„Zd8d9„Zd    S)CÚ ActionChainsaÅActionChains are a way to automate low level interactions such as mouse
    movements, mouse button actions, key press, and context menu interactions.
    This is useful for doing more complex actions like hover over and drag and
    drop.
 
    Generate user actions.
       When you call methods for actions on the ActionChains object,
       the actions are stored in a queue in the ActionChains object.
       When you call perform(), the events are fired in the order they
       are queued up.
 
    ActionChains can be used in a chain pattern::
 
        menu = driver.find_element(By.CSS_SELECTOR, ".nav")
        hidden_submenu = driver.find_element(By.CSS_SELECTOR, ".nav #submenu1")
 
        ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()
 
    Or actions can be queued up one by one, then performed.::
 
        menu = driver.find_element(By.CSS_SELECTOR, ".nav")
        hidden_submenu = driver.find_element(By.CSS_SELECTOR, ".nav #submenu1")
 
        actions = ActionChains(driver)
        actions.move_to_element(menu)
        actions.click(hidden_submenu)
        actions.perform()
 
    Either way, the actions are performed in the order they are called, one after
    another.
    éúcCs||_t||d|_dS)zØCreates a new ActionChains.
 
        :Args:
         - driver: The WebDriver instance which performs user actions.
         - duration: override the default 250 msecs of DEFAULT_MOVE_DURATION in PointerInput
        )ÚdurationN)Z_driverrÚ w3c_actions)ÚselfZdriverr    ©r ú^d:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\selenium/webdriver/common/action_chains.pyÚ__init__=szActionChains.__init__cCs|j ¡dS)zPerforms all stored actions.N)r
Úperform©r r r r rGszActionChains.performcCs$|j ¡|jjD] }| ¡qdS)zMClears actions that are already stored locally and on the remote
        end.N)r
Z clear_actionsZdevices)r Zdevicer r r Ú reset_actionsKs
 zActionChains.reset_actionsNcCs6|r| |¡|jj ¡|jj ¡|jj ¡|S)zŽClicks an element.
 
        :Args:
         - on_element: The element to click.
           If None, clicks on current mouse position.
        )Úmove_to_elementr
Úpointer_actionÚclickÚ
key_actionÚpause©r Ú
on_elementr r r rRs 
   zActionChains.clickcCs*|r| |¡|jj ¡|jj ¡|S)z°Holds down the left mouse button on an element.
 
        :Args:
         - on_element: The element to mouse down.
           If None, clicks on current mouse position.
        )rr
rÚclick_and_holdrrrr r r rbs
 
  zActionChains.click_and_holdcCs6|r| |¡|jj ¡|jj ¡|jj ¡|S)z¹Performs a context-click (right click) on an element.
 
        :Args:
         - on_element: The element to context-click.
           If None, clicks on current mouse position.
        )rr
rÚ context_clickrrrr r r rqs 
   zActionChains.context_clickcCs8|r| |¡|jj ¡tdƒD]}|jj ¡q"|S)zœDouble-clicks an element.
 
        :Args:
         - on_element: The element to double-click.
           If None, clicks on current mouse position.
        é)rr
rÚ double_clickÚrangerr)r rÚ_r r r rs 
  zActionChains.double_clickcCs| |¡| |¡|S)zòHolds down the left mouse button on the source element, then moves
        to the target element and releases the mouse button.
 
        :Args:
         - source: The element to mouse down.
         - target: The element to mouse up.
        )rÚrelease)r ÚsourceÚtargetr r r Ú drag_and_drop‘s
 
zActionChains.drag_and_dropcCs"| |¡| ||¡| ¡|S)aHolds down the left mouse button on the source element, then moves
        to the target offset and releases the mouse button.
 
        :Args:
         - source: The element to mouse down.
         - xoffset: X offset to move to.
         - yoffset: Y offset to move to.
        )rÚmove_by_offsetr)r r ÚxoffsetÚyoffsetr r r Údrag_and_drop_by_offsets    
 z$ActionChains.drag_and_drop_by_offsetcCs,|r| |¡|jj |¡|jj ¡|S)aÔSends a key press only, without releasing it. Should only be used
        with modifier keys (Control, Alt and Shift).
 
        :Args:
         - value: The modifier key to send. Values are defined in `Keys` class.
         - element: The element to send keys.
           If None, sends a key to current focused element.
 
        Example, pressing ctrl+c::
 
            ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()
        )rr
rÚkey_downrr©r ÚvalueÚelementr r r r'«s
 
 zActionChains.key_downcCs,|r| |¡|jj |¡|jj ¡|S)atReleases a modifier key.
 
        :Args:
         - value: The modifier key to send. Values are defined in Keys class.
         - element: The element to send keys.
           If None, sends a key to current focused element.
 
        Example, pressing ctrl+c::
 
            ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()
        )rr
rÚkey_uprrr(r r r r+Às
 
 zActionChains.key_upcCs |jj ||¡|jj ¡|S)zëMoving the mouse to an offset from current mouse position.
 
        :Args:
         - xoffset: X offset to move to, as a positive or negative integer.
         - yoffset: Y offset to move to, as a positive or negative integer.
        )r
rZmove_byrr)r r$r%r r r r#Ôs zActionChains.move_by_offsetcCs|jj |¡|jj ¡|S)zxMoving the mouse to the middle of an element.
 
        :Args:
         - to_element: The WebElement to move to.
        )r
rÚmove_torr)r Ú
to_elementr r r rás zActionChains.move_to_elementcCs*|jj |t|ƒt|ƒ¡|jj ¡|S)aaMove the mouse by an offset of the specified element. Offsets are
        relative to the in-view center point of the element.
 
        :Args:
         - to_element: The WebElement to move to.
         - xoffset: X offset to move to, as a positive or negative integer.
         - yoffset: Y offset to move to, as a positive or negative integer.
        )r
rr,Úintrr)r r-r$r%r r r Úmove_to_element_with_offsetís
 z(ActionChains.move_to_element_with_offsetcCs |jj |¡|jj |¡|S)z7Pause all inputs for the specified duration in seconds.)r
rrr)r Úsecondsr r r rüszActionChains.pausecCs*|r| |¡|jj ¡|jj ¡|S)z­Releasing a held mouse button on an element.
 
        :Args:
         - on_element: The element to mouse up.
           If None, releases on current mouse position.
        )rr
rrrrrr r r rs
 
  zActionChains.releasecGs*t|ƒ}|D]}| |¡| |¡q |S)z°Sends keys to current focused element.
 
        :Args:
         - keys_to_send: The keys to send.  Modifier keys constants can be found in the
           'Keys' class.
        )rr'r+)r Ú keys_to_sendÚtypingÚkeyr r r Ú    send_keyss
 
 zActionChains.send_keyscGs| |¡|j|Ž|S)zÑSends keys to an element.
 
        :Args:
         - element: The element to send keys.
         - keys_to_send: The keys to send.  Modifier keys constants can be found in the
           'Keys' class.
        )rr4)r r*r1r r r Úsend_keys_to_element"s
 
z!ActionChains.send_keys_to_element)r*cCs|jjj|d|S)zÈIf the element is outside the viewport, scrolls the bottom of the
        element to the bottom of the viewport.
 
        :Args:
         - element: Which element to scroll into the viewport.
        )Úorigin©r
Ú wheel_actionÚscroll)r r*r r r Úscroll_to_element.szActionChains.scroll_to_element©Údelta_xÚdelta_ycCs|jjj||d|S)a:Scrolls by provided amounts with the origin in the top left corner
        of the viewport.
 
        :Args:
         - delta_x: Distance along X axis to scroll using the wheel. A negative value scrolls left.
         - delta_y: Distance along Y axis to scroll using the wheel. A negative value scrolls up.
        r;r7)r r<r=r r r Úscroll_by_amount9s    zActionChains.scroll_by_amount)Ú scroll_originr<r=cCs>t|tƒstdt|ƒ›ƒ‚|jjj|j|j|j    ||d|S)a8Scrolls by provided amount based on a provided origin. The scroll
        origin is either the center of an element or the upper left of the
        viewport plus any offsets. If the origin is an element, and the element
        is not in the viewport, the bottom of the element will first be
        scrolled to the bottom of the viewport.
 
        :Args:
         - origin: Where scroll originates (viewport or element center) plus provided offsets.
         - delta_x: Distance along X axis to scroll using the wheel. A negative value scrolls left.
         - delta_y: Distance along Y axis to scroll using the wheel. A negative value scrolls up.
 
         :Raises: If the origin with offset is outside the viewport.
          - MoveTargetOutOfBoundsException - If the origin with offset is outside the viewport.
        z+Expected object of type ScrollOrigin, got: )r6ÚxÚyr<r=)
Ú
isinstancerÚ    TypeErrorÚtyper
r8r9r6Zx_offsetZy_offset)r r?r<r=r r r Úscroll_from_originEs
ûzActionChains.scroll_from_originrÚviewport©r@rAr<r=r    r6cCs.tjdtdd|jjj||||||d|S)a)Sends wheel scroll information to the browser to be processed.
 
        :Args:
         - x: starting X coordinate
         - y: starting Y coordinate
         - delta_x: the distance the mouse will scroll on the x axis
         - delta_y: the distance the mouse will scroll on the y axis
        ziscroll() has been deprecated, please use scroll_to_element(), scroll_by_amount() or scroll_from_origin().é)Ú
stacklevelrG)ÚwarningsÚwarnÚDeprecationWarningr
r8r9)r r@rAr<r=r    r6r r r r9as    ýÿzActionChains.scrollcCs|S©Nr rr r r Ú    __enter__wszActionChains.__enter__cCsdSrMr )r Ú_typeÚ_valueZ
_tracebackr r r Ú__exit__zszActionChains.__exit__)r)N)N)N)N)N)N)N)rrF) Ú__name__Ú
__module__Ú __qualname__Ú__doc__rrrrrrrr"r&r'r+r#rr/rrr4r5rr:r.r>rrEÚstrr9rNrQr r r r rs2 
 
 
 
 
 
 
 
 
   r) rUrJZ$selenium.webdriver.remote.webelementrZactions.action_builderrZactions.wheel_inputrÚutilsrrr r r r Ú<module>s