B
     hw5                 @   s  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 G dd deZ	G d	d
 d
eZ
G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdCddZG dd deZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZG d&d' d'eZG d(d) d)eZG d*d+ d+eZG d,d- d-eZG d.d/ d/eZG d0d1 d1eZG d2d3 d3eZG d4d5 d5eZG d6d7 d7eZ G d8d9 d9eZ!G d:d; d;eZ"G d<d= d=eZ#d>d? Z$d@dA Z%dBS )D    )NoSuchElementException)NoSuchFrameException)StaleElementReferenceException)WebDriverException)NoAlertPresentException)
WebElementc               @   s    e Zd ZdZdd Zdd ZdS )title_iszAn expectation for checking the title of a page.
    title is the expected title, which must be an exact match
    returns True if the title matches, false otherwise.c             C   s
   || _ d S )N)title)selfr	    r   kC:\Users\sanjo\AppData\Local\Qlobot\Launcher\ext_packages\selenium\webdriver\support\expected_conditions.py__init__#   s    ztitle_is.__init__c             C   s   | j |j kS )N)r	   )r
   driverr   r   r   __call__&   s    ztitle_is.__call__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s   r   c               @   s    e Zd ZdZdd Zdd ZdS )title_containsz An expectation for checking that the title contains a case-sensitive
    substring. title is the fragment of title expected
    returns True when the title matches, False otherwise
    c             C   s
   || _ d S )N)r	   )r
   r	   r   r   r   r   /   s    ztitle_contains.__init__c             C   s   | j |j kS )N)r	   )r
   r   r   r   r   r   2   s    ztitle_contains.__call__N)r   r   r   r   r   r   r   r   r   r   r   *   s   r   c               @   s    e Zd ZdZdd Zdd ZdS )presence_of_element_locatedz An expectation for checking that an element is present on the DOM
    of a page. This does not necessarily mean that the element is visible.
    locator - used to find the element
    returns the WebElement once it is located
    c             C   s
   || _ d S )N)locator)r
   r   r   r   r   r   <   s    z$presence_of_element_located.__init__c             C   s   t || jS )N)_find_elementr   )r
   r   r   r   r   r   ?   s    z$presence_of_element_located.__call__N)r   r   r   r   r   r   r   r   r   r   r   6   s   r   c               @   s    e Zd ZdZdd Zdd ZdS )url_containsz An expectation for checking that the current url contains a
    case-sensitive substring.
    url is the fragment of url expected,
    returns True when the url matches, False otherwise
    c             C   s
   || _ d S )N)url)r
   r   r   r   r   r   I   s    zurl_contains.__init__c             C   s   | j |jkS )N)r   current_url)r
   r   r   r   r   r   L   s    zurl_contains.__call__N)r   r   r   r   r   r   r   r   r   r   r   C   s   r   c               @   s    e Zd ZdZdd Zdd ZdS )url_matcheszAn expectation for checking the current url.
    pattern is the expected pattern, which must be an exact match
    returns True if the url matches, false otherwise.c             C   s
   || _ d S )N)pattern)r
   r   r   r   r   r   T   s    zurl_matches.__init__c             C   s    dd l }|| j|j}|d k	S )Nr   )researchr   r   )r
   r   r   matchr   r   r   r   W   s    zurl_matches.__call__N)r   r   r   r   r   r   r   r   r   r   r   P   s   r   c               @   s    e Zd ZdZdd Zdd ZdS )	url_to_bezAn expectation for checking the current url.
    url is the expected url, which must be an exact match
    returns True if the url matches, false otherwise.c             C   s
   || _ d S )N)r   )r
   r   r   r   r   r   b   s    zurl_to_be.__init__c             C   s   | j |jkS )N)r   r   )r
   r   r   r   r   r   e   s    zurl_to_be.__call__N)r   r   r   r   r   r   r   r   r   r   r    ^   s   r    c               @   s    e Zd ZdZdd Zdd ZdS )url_changeszAn expectation for checking the current url.
    url is the expected url, which must not be an exact match
    returns True if the url is different, false otherwise.c             C   s
   || _ d S )N)r   )r
   r   r   r   r   r   m   s    zurl_changes.__init__c             C   s   | j |jkS )N)r   r   )r
   r   r   r   r   r   p   s    zurl_changes.__call__N)r   r   r   r   r   r   r   r   r   r   r!   i   s   r!   c               @   s    e Zd ZdZdd Zdd ZdS )visibility_of_element_locateda7   An expectation for checking that an element is present on the DOM of a
    page and visible. Visibility means that the element is not only displayed
    but also has a height and width that is greater than 0.
    locator - used to find the element
    returns the WebElement once it is located and visible
    c             C   s
   || _ d S )N)r   )r
   r   r   r   r   r   {   s    z&visibility_of_element_located.__init__c             C   s*   yt t|| jS  tk
r$   dS X d S )NF)_element_if_visibler   r   r   )r
   r   r   r   r   r   ~   s    z&visibility_of_element_located.__call__N)r   r   r   r   r   r   r   r   r   r   r"   t   s   r"   c               @   s    e Zd ZdZdd Zdd ZdS )visibility_ofa3   An expectation for checking that an element, known to be present on the
    DOM of a page, is visible. Visibility means that the element is not only
    displayed but also has a height and width that is greater than 0.
    element is the WebElement
    returns the (same) WebElement once it is visible
    c             C   s
   || _ d S )N)element)r
   r%   r   r   r   r      s    zvisibility_of.__init__c             C   s
   t | jS )N)r#   r%   )r
   ignoredr   r   r   r      s    zvisibility_of.__call__N)r   r   r   r   r   r   r   r   r   r   r$      s   r$   Tc             C   s   |   |kr| S dS )NF)is_displayed)r%   
visibilityr   r   r   r#      s    r#   c               @   s    e Zd ZdZdd Zdd ZdS ) presence_of_all_elements_locatedz An expectation for checking that there is at least one element present
    on a web page.
    locator is used to find the element
    returns the list of WebElements once they are located
    c             C   s
   || _ d S )N)r   )r
   r   r   r   r   r      s    z)presence_of_all_elements_located.__init__c             C   s   t || jS )N)_find_elementsr   )r
   r   r   r   r   r      s    z)presence_of_all_elements_located.__call__N)r   r   r   r   r   r   r   r   r   r   r)      s   r)   c               @   s    e Zd ZdZdd Zdd ZdS )"visibility_of_any_elements_locatedz An expectation for checking that there is at least one element visible
    on a web page.
    locator is used to find the element
    returns the list of WebElements once they are located
    c             C   s
   || _ d S )N)r   )r
   r   r   r   r   r      s    z+visibility_of_any_elements_located.__init__c             C   s   dd t || jD S )Nc             S   s   g | ]}t |r|qS r   )r#   ).0r%   r   r   r   
<listcomp>   s    z?visibility_of_any_elements_located.__call__.<locals>.<listcomp>)r*   r   )r
   r   r   r   r   r      s    z+visibility_of_any_elements_located.__call__N)r   r   r   r   r   r   r   r   r   r   r+      s   r+   c               @   s    e Zd ZdZdd Zdd ZdS )"visibility_of_all_elements_locatedaI   An expectation for checking that all elements are present on the DOM of a
    page and visible. Visibility means that the elements are not only displayed
    but also has a height and width that is greater than 0.
    locator - used to find the elements
    returns the list of WebElements once they are located and visible
    c             C   s
   || _ d S )N)r   )r
   r   r   r   r   r      s    z+visibility_of_all_elements_located.__init__c             C   sH   y.t || j}x|D ]}t|ddrdS qW |S  tk
rB   dS X d S )NF)r(   )r*   r   r#   r   )r
   r   elementsr%   r   r   r   r      s    
z+visibility_of_all_elements_located.__call__N)r   r   r   r   r   r   r   r   r   r   r.      s   r.   c               @   s    e Zd ZdZdd Zdd ZdS )text_to_be_present_in_elementzn An expectation for checking if the given text is present in the
    specified element.
    locator, text
    c             C   s   || _ || _d S )N)r   text)r
   r   text_r   r   r   r      s    z&text_to_be_present_in_element.__init__c             C   s2   yt || jj}| j|kS  tk
r,   dS X d S )NF)r   r   r1   r   )r
   r   element_textr   r   r   r      s
    
z&text_to_be_present_in_element.__call__N)r   r   r   r   r   r   r   r   r   r   r0      s   r0   c               @   s    e Zd ZdZdd Zdd ZdS )#text_to_be_present_in_element_valueze
    An expectation for checking if the given text is present in the element's
    locator, text
    c             C   s   || _ || _d S )N)r   r1   )r
   r   r2   r   r   r   r      s    z,text_to_be_present_in_element_value.__init__c             C   sB   y(t || jd}|r"| j|kS dS W n tk
r<   dS X d S )NvalueF)r   r   get_attributer1   r   )r
   r   r3   r   r   r   r      s    
z,text_to_be_present_in_element_value.__call__N)r   r   r   r   r   r   r   r   r   r   r4      s   r4   c               @   s    e Zd ZdZdd Zdd ZdS )&frame_to_be_available_and_switch_to_itz An expectation for checking whether the given frame is available to
    switch to.  If the frame is available it switches the given driver to the
    specified frame.
    c             C   s
   || _ d S )N)frame_locator)r
   r   r   r   r   r      s    z/frame_to_be_available_and_switch_to_it.__init__c             C   sN   y4t | jtr$|jt|| j n|j| j dS  tk
rH   dS X d S )NTF)
isinstancer8   tuple	switch_toframer   r   )r
   r   r   r   r   r      s    
z/frame_to_be_available_and_switch_to_it.__call__N)r   r   r   r   r   r   r   r   r   r   r7      s   r7   c               @   s    e Zd ZdZdd Zdd ZdS )invisibility_of_element_locatedz An Expectation for checking that an element is either invisible or not
    present on the DOM.

    locator used to find the element
    c             C   s
   || _ d S )N)target)r
   r   r   r   r   r     s    z(invisibility_of_element_located.__init__c          	   C   sB   y$| j }t|tst||}t|dS  ttfk
r<   dS X d S )NFT)r>   r9   r   r   r#   r   r   )r
   r   r>   r   r   r   r   	  s    


z(invisibility_of_element_located.__call__N)r   r   r   r   r   r   r   r   r   r   r=      s   r=   c               @   s   e Zd ZdZdd ZdS )invisibility_of_elementz An Expectation for checking that an element is either invisible or not
    present on the DOM.

    element is either a locator (text) or an WebElement
    c             C   s
   || _ d S )N)r>   )r
   r%   r   r   r   Z__init  s    zinvisibility_of_element.__initN)r   r   r   r   Z_invisibility_of_element__initr   r   r   r   r?     s   r?   c               @   s    e Zd ZdZdd Zdd ZdS )element_to_be_clickablez^ An Expectation for checking an element is visible and enabled such that
    you can click it.c             C   s
   || _ d S )N)r   )r
   r   r   r   r   r   %  s    z element_to_be_clickable.__init__c             C   s&   t | j|}|r| r|S dS d S )NF)r"   r   
is_enabled)r
   r   r%   r   r   r   r   (  s    z element_to_be_clickable.__call__N)r   r   r   r   r   r   r   r   r   r   r@   "  s   r@   c               @   s    e Zd ZdZdd Zdd ZdS )staleness_ofz Wait until an element is no longer attached to the DOM.
    element is the element to wait for.
    returns False if the element is still attached to the DOM, true otherwise.
    c             C   s
   || _ d S )N)r%   )r
   r%   r   r   r   r   5  s    zstaleness_of.__init__c             C   s(   y| j   dS  tk
r"   dS X d S )NFT)r%   rA   r   )r
   r&   r   r   r   r   8  s
    
zstaleness_of.__call__N)r   r   r   r   r   r   r   r   r   r   rB   0  s   rB   c               @   s    e Zd ZdZdd Zdd ZdS )element_to_be_selectedz] An expectation for checking the selection is selected.
    element is WebElement object
    c             C   s
   || _ d S )N)r%   )r
   r%   r   r   r   r   E  s    zelement_to_be_selected.__init__c             C   s
   | j  S )N)r%   is_selected)r
   r&   r   r   r   r   H  s    zelement_to_be_selected.__call__N)r   r   r   r   r   r   r   r   r   r   rC   A  s   rC   c               @   s    e Zd ZdZdd Zdd ZdS )element_located_to_be_selectedz^An expectation for the element to be located is selected.
    locator is a tuple of (by, path)c             C   s
   || _ d S )N)r   )r
   r   r   r   r   r   O  s    z'element_located_to_be_selected.__init__c             C   s   t || j S )N)r   r   rD   )r
   r   r   r   r   r   R  s    z'element_located_to_be_selected.__call__N)r   r   r   r   r   r   r   r   r   r   rE   L  s   rE   c               @   s    e Zd ZdZdd Zdd ZdS )element_selection_state_to_bez An expectation for checking if the given element is selected.
    element is WebElement object
    is_selected is a Boolean."
    c             C   s   || _ || _d S )N)r%   rD   )r
   r%   rD   r   r   r   r   [  s    z&element_selection_state_to_be.__init__c             C   s   | j  | jkS )N)r%   rD   )r
   r&   r   r   r   r   _  s    z&element_selection_state_to_be.__call__N)r   r   r   r   r   r   r   r   r   r   rF   V  s   rF   c               @   s    e Zd ZdZdd Zdd ZdS )%element_located_selection_state_to_bez An expectation to locate an element and check if the selection state
    specified is in that state.
    locator is a tuple of (by, path)
    is_selected is a boolean
    c             C   s   || _ || _d S )N)r   rD   )r
   r   rD   r   r   r   r   i  s    z.element_located_selection_state_to_be.__init__c             C   s4   yt || j}| | jkS  tk
r.   dS X d S )NF)r   r   rD   r   )r
   r   r%   r   r   r   r   m  s
    z.element_located_selection_state_to_be.__call__N)r   r   r   r   r   r   r   r   r   r   rG   c  s   rG   c               @   s    e Zd ZdZdd Zdd ZdS )number_of_windows_to_bez@ An expectation for the number of windows to be a certain value.c             C   s
   || _ d S )N)num_windows)r
   rI   r   r   r   r   x  s    z number_of_windows_to_be.__init__c             C   s   t |j| jkS )N)lenwindow_handlesrI   )r
   r   r   r   r   r   {  s    z number_of_windows_to_be.__call__N)r   r   r   r   r   r   r   r   r   r   rH   u  s   rH   c               @   s    e Zd ZdZdd Zdd ZdS )new_window_is_openedzd An expectation that a new window will be opened and have the number of
    windows handles increasec             C   s
   || _ d S )N)current_handles)r
   rM   r   r   r   r     s    znew_window_is_opened.__init__c             C   s   t |jt | jkS )N)rJ   rK   rM   )r
   r   r   r   r   r     s    znew_window_is_opened.__call__N)r   r   r   r   r   r   r   r   r   r   rL     s   rL   c               @   s    e Zd ZdZdd Zdd ZdS )alert_is_presentz Expect an alert to be present.c             C   s   d S )Nr   )r
   r   r   r   r     s    zalert_is_present.__init__c             C   s&   y|j j}|S  tk
r    dS X d S )NF)r;   alertr   )r
   r   rO   r   r   r   r     s
    zalert_is_present.__call__N)r   r   r   r   r   r   r   r   r   r   rN     s   rN   c          
   C   sZ   y
| j | S  tk
r0 } z|W dd}~X Y n& tk
rT } z|W dd}~X Y nX dS )zMLooks up an element. Logs and re-raises ``WebDriverException``
    if thrown.N)find_elementr   r   )r   byer   r   r   r     s    
r   c          
   C   s6   y
| j | S  tk
r0 } z|W d d }~X Y nX d S )N)find_elementsr   )r   rQ   rR   r   r   r   r*     s    
r*   N)T)&Zselenium.common.exceptionsr   r   r   r   r   #selenium.webdriver.remote.webdriverr   objectr   r   r   r   r   r    r!   r"   r$   r#   r)   r+   r.   r0   r4   r7   r=   r?   r@   rB   rC   rE   rF   rG   rH   rL   rN   r   r*   r   r   r   r   <module>   sD   



