<s> from selenium . common . exceptions import NoSuchElementException <EOL> from selenium . common . exceptions import NoSuchFrameException <EOL> from selenium . common . exceptions import StaleElementReferenceException <EOL> from selenium . common . exceptions import WebDriverException <EOL> from selenium . common . exceptions import NoAlertPresentException <EOL> """<STR_LIT>""" <EOL> class title_is ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , title ) : <EOL> self . title = title <EOL> def __call__ ( self , driver ) : <EOL> return self . title == driver . title <EOL> class title_contains ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , title ) : <EOL> self . title = title <EOL> def __call__ ( self , driver ) : <EOL> return self . title in driver . title <EOL> class presence_of_element_located ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , locator ) : <EOL> self . locator = locator <EOL> def __call__ ( self , driver ) : <EOL> return _find_element ( driver , self . locator ) <EOL> class visibility_of_element_located ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , locator ) : <EOL> self . locator = locator <EOL> def __call__ ( self , driver ) : <EOL> try : <EOL> return _element_if_visible ( _find_element ( driver , self . locator ) ) <EOL> except StaleElementReferenceException : <EOL> return False <EOL> class visibility_of ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , element ) : <EOL> self . element = element <EOL> def __call__ ( self , ignored ) : <EOL> return _element_if_visible ( self . element ) <EOL> def _element_if_visible ( element ) : <EOL> return element if element . is_displayed ( ) else False <EOL> class presence_of_all_elements_located ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , locator ) : <EOL> self . locator = locator <EOL> def __call__ ( self , driver ) : <EOL> return _find_elements ( driver , self . locator ) <EOL> class text_to_be_present_in_element ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , locator , text_ ) : <EOL> self . locator = locator <EOL> self . text = text_ <EOL> def __call__ ( self , driver ) : <EOL> try : <EOL> element_text = _find_element ( driver , self . locator ) . text <EOL> return self . text in element_text <EOL> except StaleElementReferenceException : <EOL> return False <EOL> class text_to_be_present_in_element_value ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , locator , text_ ) : <EOL> self . locator = locator <EOL> self . text = text_ <EOL> def __call__ ( self , driver ) : <EOL> try : <EOL> element_text = _find_element ( driver , <EOL> self . locator ) . get_attribute ( "<STR_LIT:value>" ) <EOL> if element_text : <EOL> return self . text in element_text <EOL> else : <EOL> return False <EOL> except StaleElementReferenceException : <EOL> return False <EOL> class frame_to_be_available_and_switch_to_it ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , locator ) : <EOL> self . frame_locator = locator <EOL> def __call__ ( self , driver ) : <EOL> try : <EOL> if isinstance ( self . frame_locator , tuple ) : <EOL> driver . switch_to . frame ( _find_element ( driver , <EOL> self . frame_locator ) ) <EOL> else : <EOL> driver . switch_to . frame ( self . frame_locator ) <EOL> return True <EOL> except NoSuchFrameException : <EOL> return False <EOL> class invisibility_of_element_located ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , locator ) : <EOL> self . locator = locator <EOL> def __call__ ( self , driver ) : <EOL> try : <EOL> return not _find_element ( driver , self . locator ) . is_displayed ( ) <EOL> except ( NoSuchElementException , StaleElementReferenceException ) : <EOL> return True <EOL> class element_to_be_clickable ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , locator ) : <EOL> self . locator = locator <EOL> def __call__ ( self , driver ) : <EOL> element = visibility_of_element_located ( self . locator ) ( driver ) <EOL> if element and element . is_enabled ( ) : <EOL> return element <EOL> else : <EOL> return False <EOL> class staleness_of ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , element ) : <EOL> self . element = element <EOL> def __call__ ( self , ignored ) : <EOL> try : <EOL> self . element . is_enabled ( ) <EOL> return False <EOL> except StaleElementReferenceException as expected : <EOL> return True <EOL> class element_to_be_selected ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , element ) : <EOL> self . element = element <EOL> def __call__ ( self , ignored ) : <EOL> return self . element . is_selected ( ) <EOL> class element_located_to_be_selected ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , locator ) : <EOL> self . locator = locator <EOL> def __call__ ( self , driver ) : <EOL> return _find_element ( driver , self . locator ) . is_selected ( ) <EOL> class element_selection_state_to_be ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , element , is_selected ) : <EOL> self . element = element <EOL> self . is_selected = is_selected <EOL> def __call__ ( self , ignored ) : <EOL> return self . element . is_selected ( ) == self . is_selected <EOL> class element_located_selection_state_to_be ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , locator , is_selected ) : <EOL> self . locator = locator <EOL> self . is_selected = is_selected <EOL> def __call__ ( self , driver ) : <EOL> try : <EOL> element = _find_element ( driver , self . locator ) <EOL> return element . is_selected ( ) == self . is_selected <EOL> except StaleElementReferenceException : <EOL> return False <EOL> class alert_is_present ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> pass <EOL> def __call__ ( self , driver ) : <EOL> try : <EOL> alert = driver . switch_to . alert <EOL> alert . text <EOL> return alert <EOL> except NoAlertPresentException : <EOL> return False <EOL> def _find_element ( driver , by ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return driver . find_element ( * by ) <EOL> except NoSuchElementException as e : <EOL> raise e <EOL> except WebDriverException as e : <EOL> raise e <EOL> def _find_elements ( driver , by ) : <EOL> try : <EOL> return driver . find_elements ( * by ) <EOL> except WebDriverException as e : <EOL> raise e </s>
