a
    5ñ»je  ã                   @   sü   U 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 dlmZ d dlmZ d dlmZ dZeed< efZee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)ÚOptional)ÚTuple)ÚType)Ú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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   sp   || _ t|ƒ| _|| _| jdkr&t| _ttƒ}|rbz| t|ƒ¡ W n t	y`   | 
|¡ Y n0 t|ƒ| _dS )a  Constructor, takes a WebDriver instance and timeout in seconds.

        Attributes:
        -----------
        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.common.by import By
        >>> from selenium.webdriver.support.wait import WebDriverWait
        >>> from selenium.common.exceptions import ElementNotVisibleException
        >>>
        >>> # Wait until the element is no longer visible
        >>> 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&   úEE:\soccer\ml_env\Lib\site-packages\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__\   s    zWebDriverWait.__repr__Ú F)ÚmethodÚmessageÚreturnc              
   C   sš   d}d}t  ¡ | j }z|| jƒ}|r,|W S W n> | jyl } z$t|ddƒ}t|ddƒ}W Y d}~n
d}~0 0 t  ¡ |kr|qŠt  | j¡ qt|||ƒ‚dS )aŒ  Wait until the method returns a value that is not False.

        Calls the method provided with the driver as an argument until the
        return value does not evaluate to ``False``.

        Parameters:
        -----------
        method: callable(WebDriver)
            - A callable object that takes a WebDriver instance as an argument.

        message: str
            - Optional message for :exc:`TimeoutException`

        Return:
        -------
        object: T
            - The result of the last call to `method`

        Raises:
        -------
        TimeoutException
            - If 'method' does not return a truthy value within the WebDriverWait
            object's timeout

        Example:
        --------
        >>> from selenium.webdriver.common.by import By
        >>> from selenium.webdriver.support.ui import WebDriverWait
        >>> from selenium.webdriver.support import expected_conditions as EC

        # Wait until an element is visible on the page
        >>> wait = WebDriverWait(driver, 10)
        >>> element = wait.until(EC.visibility_of_element_located((By.ID, "exampleId")))
        >>> print(element.text)
        NÚscreenÚ
stacktrace)	ÚtimeÚ	monotonicr   r   r#   ÚgetattrÚsleepr   r   )r$   r0   r1   r3   r4   Úend_timeÚvalueÚexcr&   r&   r'   Úuntil_   s    $

"zWebDriverWait.untilTc                 C   sf   t  ¡ | j }z|| jƒ}|s$|W S W n | jy<   Y dS 0 t  ¡ |krLqZt  | j¡ qt|ƒ‚dS )a{  Wait until the method returns a value that is not False.

        Calls the method provided with the driver as an argument until the
        return value does not evaluate to ``False``.

        Parameters:
        -----------
        method: callable(WebDriver)
            - A callable object that takes a WebDriver instance as an argument.

        message: str
            - Optional message for :exc:`TimeoutException`

        Return:
        -------
        object: T
            - The result of the last call to `method`

        Raises:
        -------
        TimeoutException
            - If 'method' does not return False within the WebDriverWait
            object's timeout

        Example:
        --------
        >>> from selenium.webdriver.common.by import By
        >>> from selenium.webdriver.support.ui import WebDriverWait
        >>> from selenium.webdriver.support import expected_conditions as EC

        # Wait until an element is visible on the page
        >>> wait = WebDriverWait(driver, 10)
        >>> is_disappeared = wait.until_not(EC.visibility_of_element_located(
        ... (By.ID, "exampleId")))
        TN)r5   r6   r   r   r#   r8   r   r   )r$   r0   r1   r9   r:   r&   r&   r'   Ú	until_not”   s    $

zWebDriverWait.until_not)r/   )r/   )r-   r,   Ú__qualname__r   r   r   r   r   r(   r.   r   r	   r   r   Ústrr<   r=   r&   r&   r&   r'   r   )   s   ûû2*5r   )r5   Útypingr   r   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   Ú	Exceptionr   r   r   r&   r&   r&   r'   Ú<module>   s$   
