o
    Ñ·6i'  ã                   @   sV   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 )	é    )ÚNoSuchElementExceptionÚNoSuchFrameExceptionÚNoSuchWindowException)ÚAlert)ÚBy)ÚCommand)Ú
WebElementc                   @   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B eB ddfdd„Zdde
dB 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   úh/var/www/hoanhtaovolam_webdjango/env/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.

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

        Example:
            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 )zlSwitch focus to the default frame.

        Example:
            driver.switch_to.default_content()
        ÚidN)r   r   r   ÚSWITCH_TO_FRAMEr   r   r   r   Údefault_content4   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Å  Switch focus to the specified frame by index, name, or element.

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

        Example:
                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   Úframe<   s   

€ÿÿþzSwitchTo.frameÚ	type_hintc                 C   s*   | j  tjd|i¡d }|  |d ¡ dS )zö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.

        Example:
                driver.switch_to.new_window("tab")
        Útyper   ÚhandleN)r   r   r   Ú
NEW_WINDOWÚ_w3c_window)r   r&   r   r   r   r   Ú
new_windowS   s   	zSwitchTo.new_windowc                 C   s   | j  tj¡ dS )zØSwitch focus to the parent browsing context.

        If the current context is already the top level browsing context, it remains unchanged.

        Example:
                driver.switch_to.parent_frame()
        N)r   r   r   ÚSWITCH_TO_PARENT_FRAMEr   r   r   r   Úparent_frame_   s   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.

        Example:
            driver.switch_to.window("main")
        N)r*   )r   r.   r   r   r   Úwindowi   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_handleu   s   z)SwitchTo._w3c_window.<locals>.send_handlezreturn window.name)r   r   Úcurrent_window_handleÚwindow_handlesÚexecute_script)r   r.   r2   Úoriginal_handleÚhandlesr(   Úcurrent_namer   r   r   r*   t   s   ÿözSwitchTo._w3c_window)r
   N)N)Ú__name__Ú
__module__Ú__qualname__r   Úpropertyr   r   r   r   r   r    Úintr%   r+   r-   r/   r*   r   r   r   r   r	      s    




r	   N)Úselenium.common.exceptionsr   r   r   Úselenium.webdriver.common.alertr   Úselenium.webdriver.common.byr   Ú!selenium.webdriver.remote.commandr   Ú$selenium.webdriver.remote.webelementr   r	   r   r   r   r   Ú<module>   s   