
    ,hK5                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	lmZ dd
l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)
WebElement   )ActionBuilder)KeyInput)PointerInput)ScrollOrigin)
WheelInput)keys_to_typing)	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),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.
    Nc                    || _         d}d}d}|Nt        |t              r>|D ]9  }t        |t              r|}t        |t              r|}t        |t
              s8|}; t        |||||      | _        y)zCreates a new ActionChains.

        :Args:
         - driver: The WebDriver instance which performs user actions.
         - duration: override the default 250 msecs of DEFAULT_MOVE_DURATION in PointerInput
        N)mousekeyboardwheelduration)_driver
isinstancelistr
   r	   r   r   w3c_actions)selfdriverr   devicesr   r   r   devices           i/var/www/html/Resume-Scraper/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)zMClears actions that are already stored locally and on the remote
        end.N)r   clear_actionsr   )r   r   s     r   reset_actionszActionChains.reset_actions`   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.clickg   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   r0   zActionChains.click_and_holdw   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   r2   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   r5   zActionChains.double_click   s_       ,''446q 	0A''--/	0 r    c                J    | j                  |       | j                  |       | S )zHolds 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.
        )r0   release)r   sourcetargets      r   drag_and_dropzActionChains.drag_and_drop   s#     	F#Vr    c                l    | j                  |       | j                  ||       | j                          | S )a  Holds 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.
        )r0   move_by_offsetr9   )r   r:   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  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()
        )r*   r   r+   key_downr)   r,   r   valueelements      r   rC   zActionChains.key_down   sJ     JJw##,,U3''--/r    c                    |r| j                  |       | j                  j                  j                  |       | j                  j                  j                          | S )at  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,   rD   s      r   rH   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 )aa  Move 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   r)   rL   intr+   r,   )r   rM   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                  |       | S )z7Pause all inputs for the specified duration in seconds.)r   r)   r,   r+   )r   secondss     r   r,   zActionChains.pause  s=     	''--g6##))'2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)   r9   r+   r,   r-   s     r   r9   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   rC   rH   )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*   rX   )r   rF   rU   s      r   send_keys_to_elementz!ActionChains.send_keys_to_element7  s#     	

7%r    c                R    | j                   j                  j                  |       | S )zIf 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   rF   s     r   scroll_to_elementzActionChains.scroll_to_elementC  s&     	%%,,G,<r    c                T    | j                   j                  j                  ||       | 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.
        )delta_xdelta_yr]   )r   rb   rc   s      r   scroll_by_amountzActionChains.scroll_by_amountN  s(     	%%,,Wg,Nr    c                    t        |t              st        dt        |             | j                  j
                  j                  |j                  |j                  |j                  ||       | S )a8  Scrolls 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: )r\   xyrb   rc   )
r   r   	TypeErrortyper   r^   r_   r\   x_offsety_offset)r   scroll_originrb   rc   s       r   scroll_from_originzActionChains.scroll_from_originZ  sn      -6I$}J]I^_``%%,, ''$$$$ 	- 	
 r    c                    | S N r#   s    r   	__enter__zActionChains.__enter__x  s    r    c                     y ro   rp   )r   _type_value
_tracebacks       r   __exit__zActionChains.__exit__{  s    r    )   N)r   r   r   rO   r   zlist[AnyDevice] | NonereturnNone)rx   ry   ro   )r.   WebElement | Nonerx   r   )r:   r   r;   r   rx   r   )r:   r   r?   rO   r@   rO   rx   r   )rE   strrF   rz   rx   r   )r?   rO   r@   rO   rx   r   )rM   r   rx   r   )rM   r   r?   rO   r@   rO   rx   r   )rR   zfloat | intrx   r   )rU   r{   rx   r   )rF   r   rU   r{   rx   r   )rF   r   rx   r   )rb   rO   rc   rO   rx   r   )rl   r   rb   rO   rc   rO   rx   r   )rx   r   )__name__
__module____qualname____doc__r   r"   r&   r*   r0   r2   r5   r<   rA   rC   rH   r>   r(   rP   r,   r9   rX   rZ   r`   rd   rm   rq   rv   rp   r    r   r   r   &   s|    @q*##   
*(

	
<r    r   N)r   
__future__r   rV   r   r   $selenium.webdriver.remote.webelementr   actions.action_builderr   actions.key_inputr	   actions.pointer_inputr
   actions.wheel_inputr   r   utilsr   #selenium.webdriver.remote.webdriverr   	AnyDevicer   rp   r    r   <module>r      sK   " ' "    ; 1 ' / - + !=,*45	V Vr    