
    /_iu6                        d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZmZ ddlmZ dd	lmZ erdd
lmZ eee	ef   Z G d d      Zy)z The ActionChains implementation.    )annotations)TYPE_CHECKINGUnion)ActionBuilder)KeyInput)PointerInput)ScrollOrigin
WheelInput)keys_to_typing)
WebElement)	WebDriverc                      e Zd ZdZdddZddZddZdddZdddZdddZ	ddd	Z
dd
Zd dZdd!dZdd!dZd"dZd#dZd$dZd%dZdddZd&dZd'dZd(dZd)dZd*dZd+dZddZy),ActionChainsa0  Automate low-level interactions like mouse movements, button actions, key presses, and context menus.

    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.
    Nc                    || _         d}d}d}|Nt        |t              r>|D ]9  }t        |t              r|}t        |t              r|}t        |t
              s8|}; t        |||||      | _        y)a|  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
            devices: Optional list of input devices (PointerInput, KeyInput, WheelInput) to use.
                If not provided, default devices will be created.
        N)mousekeyboardwheelduration)_driver
isinstancelistr   r   r
   r   w3c_actions)selfdriverr   devicesr   r   r   devices           f/var/www/html/land_sniper/venv/lib/python3.12/site-packages/selenium/webdriver/common/action_chains.py__init__zActionChains.__init__G   s~     :gt#<! #fl3"Efh/%Hfj1"E# )uxW\gop    c                8    | j                   j                          y)zPerforms all stored actions.N)r   performr   s    r   r!   zActionChains.perform^   s      "r   c                    | j                   j                          | j                   j                  D ]  }|j                           y)z3Clear actions stored locally and on the remote end.N)r   clear_actionsr   )r   r   s     r   reset_actionszActionChains.reset_actionsb   s;    &&(&&.. 	#F  "	#r   c                   |r| j                  |       | j                  j                  j                          | j                  j                  j                          | j                  j                  j                          | S )zClicks 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_elements     r   r)   zActionChains.clickh   sb       ,''--/##))+##))+r   c                    |r| j                  |       | j                  j                  j                          | j                  j                  j                          | S )zHolds down the left mouse button on an element.

        Args:
            on_element: The element to mouse down.
                If None, clicks on current mouse position.
        )r'   r   r(   click_and_holdr*   r+   r,   s     r   r/   zActionChains.click_and_holdx   sJ       ,''668##))+r   c                   |r| j                  |       | j                  j                  j                          | j                  j                  j                          | j                  j                  j                          | S )zPerforms a context-click (right click) on an element.

        Args:
            on_element: The element to context-click.
                If None, clicks on current mouse position.
        )r'   r   r(   context_clickr*   r+   r,   s     r   r1   zActionChains.context_click   sb       ,''557##))+##))+r   c                    |r| j                  |       | j                  j                  j                          t	        d      D ]&  }| j                  j
                  j                          ( | S )zDouble-clicks an element.

        Args:
            on_element: The element to double-click.
                If None, clicks on current mouse position.
           )r'   r   r(   double_clickranger*   r+   )r   r-   _s      r   r4   zActionChains.double_click   s_       ,''446q 	0A''--/	0 r   c                J    | j                  |       | j                  |       | S )zHold down the left mouse button on an element, then move to target and release.

        Args:
            source: The element to mouse down.
            target: The element to mouse up.
        )r/   release)r   sourcetargets      r   drag_and_dropzActionChains.drag_and_drop   s#     	F#Vr   c                l    | j                  |       | j                  ||       | j                          | S )zHold down the left mouse button on an element, then move by offset and release.

        Args:
            source: The element to mouse down.
            xoffset: X offset to move to.
            yoffset: Y offset to move to.
        )r/   move_by_offsetr8   )r   r9   xoffsetyoffsets       r   drag_and_drop_by_offsetz$ActionChains.drag_and_drop_by_offset   s0     	F#GW-r   c                    |r| j                  |       | j                  j                  j                  |       | j                  j                  j                          | S )a  Send a key press only without releasing it (modifier keys only).

        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()
        )r)   r   r*   key_downr(   r+   r   valueelements      r   rB   zActionChains.key_down   sJ     JJw##,,U3''--/r   c                    |r| j                  |       | j                  j                  j                  |       | j                  j                  j                          | S )az  Releases 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()
        )r)   r   r*   key_upr(   r+   rC   s      r   rG   zActionChains.key_up   sJ     JJw##**51''--/r   c                    | j                   j                  j                  ||       | j                   j                  j	                          | S )zMoving 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   r(   move_byr*   r+   )r   r>   r?   s      r   r=   zActionChains.move_by_offset   s=     	''//A##))+r   c                    | j                   j                  j                  |       | j                   j                  j	                          | S )zxMoving the mouse to the middle of an element.

        Args:
            to_element: The WebElement to move to.
        )r   r(   move_tor*   r+   )r   
to_elements     r   r'   zActionChains.move_to_element   s;     	''//
;##))+r   c                    | j                   j                  j                  |t        |      t        |             | j                   j                  j                          | S )ag  Move the mouse to an element with the specified offsets.

        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   r(   rK   intr*   r+   )r   rL   r>   r?   s       r   move_to_element_with_offsetz(ActionChains.move_to_element_with_offset   sG     	''//
CL#g,W##))+r   c                    | j                   j                  j                  |       | j                   j                  j                  t	        |             | S )z7Pause all inputs for the specified duration in seconds.)r   r(   r+   r*   rN   )r   secondss     r   r+   zActionChains.pause  s?    ''--g6##))#g,7r   c                    |r| j                  |       | j                  j                  j                          | j                  j                  j                          | S )zReleasing a held mouse button on an element.

        Args:
            on_element: The element to mouse up.
                If None, releases on current mouse position.
        )r'   r   r(   r8   r*   r+   r,   s     r   r8   zActionChains.release  sJ       ,''//1##))+r   c                n    t        |      }|D ]$  }| j                  |       | j                  |       & | S )zSends keys to current focused element.

        Args:
            keys_to_send: The keys to send. Modifier keys constants can be found in the
                'Keys' class.
        )r   rB   rG   )r   keys_to_sendtypingkeys       r   	send_keyszActionChains.send_keys#  s<      - 	CMM#KK	 r   c                F    | j                  |        | j                  |  | S )zSends 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.
        )r)   rW   )r   rE   rT   s      r   send_keys_to_elementz!ActionChains.send_keys_to_element2  s#     	

7%r   c                R    | j                   j                  j                  |       | S )zScroll the element into the viewport if it's outside it.

        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   rE   s     r   scroll_to_elementzActionChains.scroll_to_element>  s&     	%%,,G,<r   c                T    | j                   j                  j                  ||       | S )a  Scroll by a provided amount with the origin in the top left corner.

        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.
        )delta_xdelta_yr\   )r   ra   rb   s      r   scroll_by_amountzActionChains.scroll_by_amountI  s(     	%%,,Wg,Nr   c                    t        |t              st        dt        |             | j                  j
                  j                  |j                  |j                  |j                  ||       | S )a!  Scroll by a provided amount based on a scroll origin (element or viewport).

        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:
            scroll_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:
            MoveTargetOutOfBoundsException: If the origin with offset is outside the viewport.
        z+Expected object of type ScrollOrigin, got: )r[   xyra   rb   )
r   r	   	TypeErrortyper   r]   r^   r[   x_offsety_offset)r   scroll_originra   rb   s       r   scroll_from_originzActionChains.scroll_from_originV  sn      -6I$}J]I^_``%%,, ''$$$$ 	- 	
 r   c                    | S N r"   s    r   	__enter__zActionChains.__enter__t  s    r   c                     y rn   ro   )r   _type_value
_tracebacks       r   __exit__zActionChains.__exit__w  s    r   )   N)r   r   r   rN   r   zlist[AnyDevice] | NonereturnNone)rw   rx   rn   )r-   WebElement | Nonerw   r   )r9   r   r:   r   rw   r   )r9   r   r>   rN   r?   rN   rw   r   )rD   strrE   ry   rw   r   )r>   rN   r?   rN   rw   r   )rL   r   rw   r   )rL   r   r>   rN   r?   rN   rw   r   )rQ   zfloat | intrw   r   )rT   rz   rw   r   )rE   r   rT   rz   rw   r   )rE   r   rw   r   )ra   rN   rb   rN   rw   r   )rk   r	   ra   rN   rb   rN   rw   r   )rw   r   )__name__
__module____qualname____doc__r   r!   r%   r)   r/   r1   r4   r;   r@   rB   rG   r=   r'   rO   r+   r8   rW   rY   r_   rc   rl   rp   ru   ro   r   r   r   r   $   s|     Dq.##   	((
	
	<r   r   N)r~   
__future__r   rU   r   r   0selenium.webdriver.common.actions.action_builderr   +selenium.webdriver.common.actions.key_inputr   /selenium.webdriver.common.actions.pointer_inputr   -selenium.webdriver.common.actions.wheel_inputr	   r
   selenium.webdriver.common.utilsr   $selenium.webdriver.remote.webelementr   #selenium.webdriver.remote.webdriverr   	AnyDevicer   ro   r   r   <module>r      sE   " ' " ' J @ H R : ;=,*45	T Tr   