o
    5@HhÇ  ã                   @   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„Zedefdd„ƒZedefdd„ƒZdd	d
„Z	de
eeef ddfdd„Zddee ddfdd„Zddd„Zdeddfdd„Zdeddfdd„ZdS )ÚSwitchToÚreturnNc                 C   s   dd l }| |¡| _d S )Nr   )ÚweakrefÚproxyÚ_driver)ÚselfÚdriverr   © r   úc/home/air/sanwanet/gpt-api/venv/lib/python3.10/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   ÚW3C_GET_ACTIVE_ELEMENT©r   r   r   r   Úactive_element"   ó   	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_referencec                 C   s‚   t |tƒr5z
| j tj|¡}W n% ty4   z
| j tj|¡}W n ty1 } zt|ƒ|‚d}~ww Y nw | 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   Úfind_elementr   ÚIDr   ÚNAMEr   r   r   r    )r   r"   Úexcr   r   r   ÚframeD   s   

€ÿÿþzSwitchTo.frameÚ	type_hintc                 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   Ú
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   ÚSWITCH_TO_PARENT_FRAMEr   r   r   r   Úparent_framel   r   zSwitchTo.parent_frameÚwindow_namec                 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   r2   r   r   r   Úwindoww   s   zSwitchTo.windowc                    sr   ‡ fdd„}z||ƒ W d S  t y8   ˆ jj}ˆ jj}|D ]}||ƒ ˆ j d¡}||kr2 Y d S q||ƒ ‚ w )Nc                    s   ˆ j  tjd| i¡ d S )Nr,   )r   r   r   ÚSWITCH_TO_WINDOW)Úhr   r   r   Úsend_handle…   s   z)SwitchTo._w3c_window.<locals>.send_handlezreturn window.name)r   r   Úcurrent_window_handleÚwindow_handlesÚexecute_script)r   r2   r6   Úoriginal_handleÚhandlesr,   Úcurrent_namer   r   r   r.   „   s   ÿözSwitchTo._w3c_window)r   N)N)Ú__name__Ú
__module__Ú__qualname__r   Úpropertyr	   r   r   r   r!   r   r$   Úintr)   r   r/   r1   r3   r.   r   r   r   r   r      s    




r   N)Útypingr   r   Úselenium.common.exceptionsr   r   r   Úselenium.webdriver.common.alertr   Úselenium.webdriver.common.byr   Ú$selenium.webdriver.remote.webelementr	   Úcommandr   r   r   r   r   r   Ú<module>   s   