#NEWLINE# def bind_row_action( action_name ) : #NEWLINE# #INDENT# 'A decorator to bind table region method to an actual row action button.\n\n    Many table actions when started (by clicking a corresponding button\n    in UI) lead to some form showing up. To further interact with this form,\n    a Python/ Selenium wrapper needs to be created for it. It is very\n    convenient to return this newly created wrapper in the same method that\n    initiates clicking an actual action button. Row action could be\n    either primary (if its name is written right away on row action\n    button) or secondary (if its name is inside of a button drop-down). Binding\n    the method to a button and toggling the button drop-down open (in case\n    a row action is secondary) is performed behind the scenes in this\n    decorator.\n\n    .. param:: action_name\n\n        Part of the action button id which is specific to action itself. It\n        is safe to use action `name` attribute from the dashboard tables.py\n        code.\n    ' #NEWLINE# primary_action_locator = ( by . By . CSS_SELECTOR , 'td.actions_column *.btn:nth-child(1)' ) #NEWLINE# secondary_actions_opener_locator = ( by . By . CSS_SELECTOR , 'td.actions_column > .btn-group > *.btn:nth-child(2)' ) #NEWLINE# secondary_actions_locator = ( by . By . CSS_SELECTOR , 'td.actions_column > .btn-group > ul.row_actions > li > a, button' ) #NEWLINE# def decorator( method ) : #NEWLINE# #INDENT# @ functools . wraps ( method ) #NEWLINE# def wrapper( table , row ) : #NEWLINE# #INDENT# def find_action( element ) : #NEWLINE# #INDENT# pattern = ( '__action_%s' % action_name ) #NEWLINE# return element . get_attribute ( 'id' ) . endswith ( pattern ) #NEWLINE# #UNINDENT# action_element = row . _get_element ( * primary_action_locator ) #NEWLINE# if ( not find_action ( action_element ) ) : #NEWLINE# #INDENT# action_element = None #NEWLINE# row . _get_element ( * secondary_actions_opener_locator ) . click ( ) #NEWLINE# for element in row . _get_elements ( * secondary_actions_locator ) : #NEWLINE# #INDENT# if find_action ( element ) : #NEWLINE# #INDENT# action_element = element #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( action_element is None ) : #NEWLINE# #INDENT# msg = ( "Could not bind method '%s' to action control '%s'" % ( method . __name__ , action_name ) ) #NEWLINE# raise ValueError ( msg ) #NEWLINE# #UNINDENT# return method ( table , action_element , row ) #NEWLINE# #UNINDENT# return wrapper #NEWLINE# #UNINDENT# return decorator