a
    ¾Ê.cÙ  ã                   @   sV   d dl 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 G dd„ dƒZd	S )
é   )ÚCommandé    )ÚNoSuchElementExceptionÚNoSuchFrameExceptionÚNoSuchWindowException)ÚAlert)ÚBy)Ú
WebElementc                   @   sˆ   e Zd Zdd„ Zeedœdd„ƒZeedœdd„ƒZddœd	d
„Z	ddœdd„Z
dddœdd„Zddœdd„Zddœdd„Zdd„ ZdS )ÚSwitchToc                 C   s   dd l }| |¡| _d S )Nr   )ÚweakrefÚproxyÚ_driver)ÚselfZdriverr   © r   ú]/var/www/brookimports/venv/lib/python3.9/site-packages/selenium/webdriver/remote/switch_to.pyÚ__init__   s    zSwitchTo.__init__)Úreturnc                 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.alertNc                 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_contentc                 C   sz   t |tƒrbz| j tj|¡}W nB ty`   z| j tj|¡}W n tyZ   t|ƒ‚Y n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])
        r   N)Ú
isinstanceÚstrr   Zfind_elementr   ZIDr   ÚNAMEr   r   r   r   )r   Zframe_referencer   r   r   ÚframeF   s    
zSwitchTo.framec                 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   Z	type_hintr   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_framen   s    
zSwitchTo.parent_framec                 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   Úwindow_namer   r   r   Úwindowz   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$   r%   r'   r#   r   r   r   r   r
      s   r
   N)Úcommandr   Zselenium.common.exceptionsr   r   r   Zselenium.webdriver.common.alertr   Zselenium.webdriver.common.byr   Z$selenium.webdriver.remote.webelementr	   r
   r   r   r   r   Ú<module>   s
   