B
     ¸h  ã               @   sl   d dl mZ ddlmZ ddlmZ ddlmZmZm	Z	 ye
 W n ek
rX   eZ
Y nX G dd„ dƒZdS )	é   )ÚCommandé    )ÚAlert)ÚBy)ÚNoSuchElementExceptionÚNoSuchFrameExceptionÚNoSuchWindowExceptionc               @   sT   e Zd Zdd„ Zedd„ ƒZedd„ ƒZdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚSwitchToc             C   s
   || _ d S )N)Ú_driver)ÚselfÚdriver© r   ú`C:\Users\sanjo\AppData\Local\Qlobot\Launcher\ext_packages\selenium\webdriver\remote\switch_to.pyÚ__init__   s    zSwitchTo.__init__c             C   s0   | j jr| j  tj¡d S | j  tj¡d S dS )z–
        Returns the element with focus, or BODY if nothing has focus.

        :Usage:
            element = driver.switch_to.active_element
        ÚvalueN)r
   Úw3cÚexecuter   ÚW3C_GET_ACTIVE_ELEMENTÚGET_ACTIVE_ELEMENT)r   r   r   r   Úactive_element!   s    zSwitchTo.active_elementc             C   s   t | jƒ}|j |S )zu
        Switches focus to an alert on the page.

        :Usage:
            alert = driver.switch_to.alert
        )r   r
   Útext)r   Úalertr   r   r   r   .   s    
zSwitchTo.alertc             C   s   | j  tjddi¡ dS )zt
        Switch focus to the default frame.

        :Usage:
            driver.switch_to.default_content()
        ÚidN)r
   r   r   ÚSWITCH_TO_FRAME)r   r   r   r   Údefault_content:   s    zSwitchTo.default_contentc             C   s†   t |tƒrn| jjrny| j tj|¡}W nF tk
rl   y| j tj|¡}W n tk
rf   t	|ƒ‚Y nX Y nX | 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Ú
basestringr
   r   Úfind_elementr   ÚIDr   ÚNAMEr   r   r   r   )r   Úframe_referencer   r   r   ÚframeC   s    zSwitchTo.framec             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_FRAME)r   r   r   r   Úparent_frame[   s    zSwitchTo.parent_framec             C   s2   | j jr|  |¡ dS d|i}| j  tj|¡ 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Úname)r
   r   Ú_w3c_windowr   r   ÚSWITCH_TO_WINDOW)r   Úwindow_nameÚdatar   r   r   Úwindowe   s
    

zSwitchTo.windowc          
      sŠ   ‡ fdd„}y||ƒ W nl t k
r„ } zNˆ jj}ˆ jj}x,|D ]$}||ƒ ˆ j d¡}||kr@d S q@W ||ƒ |‚W d d }~X Y nX d S )Nc                s   ˆ j  tjd| i¡ d S )NÚhandle)r
   r   r   r&   )Úh)r   r   r   Úsend_handlev   s    z)SwitchTo._w3c_window.<locals>.send_handlezreturn window.name)r   r
   Úcurrent_window_handleÚwindow_handlesÚexecute_script)r   r'   r,   ÚeZoriginal_handleZhandlesr*   Zcurrent_namer   )r   r   r%   u   s    
zSwitchTo._w3c_windowN)Ú__name__Ú
__module__Ú__qualname__r   Úpropertyr   r   r   r!   r#   r)   r%   r   r   r   r   r	      s   	
r	   N)Úcommandr   Zselenium.webdriver.common.alertr   Úselenium.webdriver.common.byr   Úselenium.common.exceptionsr   r   r   r   Ú	NameErrorÚstrr	   r   r   r   r   Ú<module>   s   
