a
    RýIhÇ  ã                   @   sf   d dl mZmZ d dlmZmZmZ d dlmZ d dl	m
Z
 d dlmZ ddlmZ G dd	„ d	ƒZd
S )é    )ÚOptionalÚUnion)ÚNoSuchElementExceptionÚNoSuchFrameExceptionÚNoSuchWindowException)ÚAlert)ÚBy)Ú
WebElementé   )ÚCommandc                   @   sª   e Zd Zddœdd„Zeedœdd„ƒZeedœdd„ƒZddœd	d
„Z	e
eeef ddœdd„Zdee ddœdd„Zddœdd„Zeddœdd„Zeddœdd„ZdS )ÚSwitchToN)Úreturnc                 C   s   dd l }| |¡| _d S )Nr   )ÚweakrefÚproxyÚ_driver)ÚselfZdriverr   © r   ú]/var/www/html/venv_bot_3.9/lib/python3.9/site-packages/selenium/webdriver/remote/switch_to.pyÚ__init__   s    zSwitchTo.__init__c                 C   s   | j  tj¡d S )z¡Returns the element with focus, or BODY if nothing has focus.

        :Usage:
            ::

                element = driver.switch_to.active_element
        Úvalue)r   Úexecuter   ZW3C_GET_ACTIVE_ELEMENT©r   r   r   r   Úactive_element"   s    	zSwitchTo.active_elementc                 C   s   t | jƒ}|j}|S )z€Switches focus to an alert on the page.

        :Usage:
            ::

                alert = driver.switch_to.alert
        )r   r   Útext)r   ÚalertÚ_r   r   r   r   -   s    	
zSwitchTo.alertc                 C   s   | j  tjddi¡ dS )zSwitch focus to the default frame.

        :Usage:
            ::

                driver.switch_to.default_content()
        ÚidN)r   r   r   ÚSWITCH_TO_FRAMEr   r   r   r   Údefault_content:   s    zSwitchTo.default_content)Úframe_referencer   c                 C   sŽ   t |tƒrvz| j tj|¡}W nV tyt   z| j tj|¡}W n. tyn } zt|ƒ|‚W Y d}~n
d}~0 0 Y n0 | j 	t
jd|i¡ dS )aï  Switches focus to the specified frame, by index, name, or
        webelement.

        :Args:
         - frame_reference: The name of the window to switch to, an integer representing the index,
                            or a webelement that is an (i)frame to switch to.

        :Usage:
            ::

                driver.switch_to.frame("frame_name")
                driver.switch_to.frame(1)
                driver.switch_to.frame(driver.find_elements(By.TAG_NAME, "iframe")[0])
        Nr   )Ú
isinstanceÚstrr   Zfind_elementr   ZIDr   ÚNAMEr   r   r   r   )r   r   Úexcr   r   r   ÚframeD   s    
&zSwitchTo.frame)Ú	type_hintr   c                 C   s*   | j  tjd|i¡d }|  |d ¡ dS )a  Switches to a new top-level browsing context.

        The type hint can be one of "tab" or "window". If not specified the
        browser will automatically select it.

        :Usage:
            ::

                driver.switch_to.new_window("tab")
        Útyper   ÚhandleN)r   r   r   Z
NEW_WINDOWÚ_w3c_window)r   r%   r   r   r   r   Ú
new_window^   s    zSwitchTo.new_windowc                 C   s   | j  tj¡ dS )zàSwitches focus to the parent context. If the current context is the
        top level browsing context, the context remains unchanged.

        :Usage:
            ::

                driver.switch_to.parent_frame()
        N)r   r   r   ZSWITCH_TO_PARENT_FRAMEr   r   r   r   Úparent_framel   s    	zSwitchTo.parent_frame)Úwindow_namer   c                 C   s   |   |¡ dS )zßSwitches focus to the specified window.

        :Args:
         - window_name: The name or window handle of the window to switch to.

        :Usage:
            ::

                driver.switch_to.window("main")
        N)r(   )r   r+   r   r   r   Úwindoww   s    zSwitchTo.windowc                    sx   ‡ fdd„}z||ƒ W nZ t yr   ˆ jj}ˆ jj}|D ](}||ƒ ˆ j d¡}||kr: Y d S q:||ƒ ‚ Y n0 d S )Nc                    s   ˆ j  tjd| i¡ d S )Nr'   )r   r   r   ZSWITCH_TO_WINDOW)Úhr   r   r   Úsend_handle…   s    z)SwitchTo._w3c_window.<locals>.send_handlezreturn window.name)r   r   Zcurrent_window_handleZwindow_handlesZexecute_script)r   r+   r.   Zoriginal_handleZhandlesr'   Zcurrent_namer   r   r   r(   „   s    
zSwitchTo._w3c_window)N)Ú__name__Ú
__module__Ú__qualname__r   Úpropertyr	   r   r   r   r   r   r!   Úintr$   r   r)   r*   r,   r(   r   r   r   r   r      s   

r   N)Útypingr   r   Zselenium.common.exceptionsr   r   r   Zselenium.webdriver.common.alertr   Zselenium.webdriver.common.byr   Z$selenium.webdriver.remote.webelementr	   Úcommandr   r   r   r   r   r   Ú<module>   s   