U
    Pf                     @   s   U d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d d	l
mZ d d
lmZ d dlmZ dZeed< efZejeje  ed< edeeef dZedZG dd dee ZdS )    N)Callable)Generic)Literal)TypeVar)Union)NoSuchElementException)TimeoutException)WaitExcTypes)	WebDriver)
WebElementg      ?POLL_FREQUENCYIGNORED_EXCEPTIONSD)boundTc                   @   s   e Zd Zedfeeeeje dddZ	dd Z
deegeed ef f eed	d
dZdeegef eeeed f d	ddZdS )WebDriverWaitN)drivertimeoutpoll_frequencyignored_exceptionsc                 C   sr   || _ t|| _|| _| jdkr&t| _tt}|rdz|t| W n t	k
rb   |
| Y nX t|| _dS )aV  Constructor, takes a WebDriver instance and timeout in seconds.

        :Args:
         - driver - Instance of WebDriver (Ie, Firefox, Chrome or Remote) or a WebElement
         - timeout - Number of seconds before timing out
         - poll_frequency - sleep interval between calls
           By default, it is 0.5 second.
         - ignored_exceptions - iterable structure of exception classes ignored during calls.
           By default, it contains NoSuchElementException only.

        Example::

         from selenium.webdriver.support.wait import WebDriverWait 

         element = WebDriverWait(driver, 10).until(lambda x: x.find_element(By.ID, "someId")) 

         is_disappeared = WebDriverWait(driver, 30, 1, (ElementNotVisibleException)).\ 

                     until_not(lambda x: x.find_element(By.ID, "someId").is_displayed())
        r   N)_driverfloat_timeout_pollr   listr   extenditer	TypeErrorappendtuple_ignored_exceptions)selfr   r   r   r   
exceptions r#   C/tmp/pip-unpacked-wheel-ds5t_0qj/selenium/webdriver/support/wait.py__init__(   s    

zWebDriverWait.__init__c                 C   s(   dt | j dt | j d| jj dS )N<.z (session="z")>)type
__module____name__r   Z
session_id)r!   r#   r#   r$   __repr__N   s    zWebDriverWait.__repr__ F)methodmessagereturnc              
   C   s   d}d}t  | j }z|| j}|r,|W S W n< | jk
rj } zt|dd}t|dd}W 5 d}~X Y nX t | j t  |krqqt|||dS )a  Calls the method provided with the driver as an argument until the         return value does not evaluate to ``False``.

        :param method: callable(WebDriver)
        :param message: optional message for :exc:`TimeoutException`
        :returns: the result of the last call to `method`
        :raises: :exc:`selenium.common.exceptions.TimeoutException` if timeout occurs
        Nscreen
stacktrace)	time	monotonicr   r   r    getattrsleepr   r   )r!   r-   r.   r0   r1   end_timevalueexcr#   r#   r$   untilQ   s    	

zWebDriverWait.untilTc                 C   sh   t  | j }z|| j}|s$|W S W n | jk
r>   Y dS X t | j t  |krq\qt|dS )a  Calls the method provided with the driver as an argument until the         return value evaluates to ``False``.

        :param method: callable(WebDriver)
        :param message: optional message for :exc:`TimeoutException`
        :returns: the result of the last call to `method`, or
                  ``True`` if `method` has raised one of the ignored exceptions
        :raises: :exc:`selenium.common.exceptions.TimeoutException` if timeout occurs
        TN)r2   r3   r   r   r    r5   r   r   )r!   r-   r.   r6   r7   r#   r#   r$   	until_notk   s    


zWebDriverWait.until_not)r,   )r,   )r*   r)   __qualname__r   r   r   typingOptionalr	   r%   r+   r   r   r   r   strr9   r:   r#   r#   r#   r$   r   '   s   &*r   )r2   r<   r   r   r   r   r   Zselenium.common.exceptionsr   r   Zselenium.typesr	   Z#selenium.webdriver.remote.webdriverr
   Z$selenium.webdriver.remote.webelementr   r   r   __annotations__r   TupleType	Exceptionr   r   r   r#   r#   r#   r$   <module>   s"    