def bind_row_action(action_name):
 primary_action_locator = (by.By.CSS_SELECTOR, 'td.actions_column *.btn:nth-child(1)')
 secondary_actions_opener_locator = (by.By.CSS_SELECTOR, 'td.actions_column > .btn-group > *.btn:nth-child(2)')
 secondary_actions_locator = (by.By.CSS_SELECTOR, 'td.actions_column > .btn-group > ul.row_actions > li > a, button')
 def decorator(method):
  @functools.wraps(method)
  def wrapper(table, row):
   def find_action(element):
    pattern = ('__action_%s' % action_name)
    return element.get_attribute('id').endswith(pattern)
   action_element = row._get_element(*primary_action_locator)
   if (not find_action(action_element)):
    action_element = None
    row._get_element(*secondary_actions_opener_locator).click()
    for element in row._get_elements(*secondary_actions_locator):
     if find_action(element):
      action_element = element
      break
   if (action_element is None):
    msg = ("Could not bind method '%s' to action control '%s'" % (method.__name__, action_name))
    raise ValueError(msg)
   return method(table, action_element, row)
  return wrapper
 return decorator

def bind_row_action ( action_name ) : primary_action_locator = ( by . By . CSS_SELECTOR , 'td.actions_column *.btn:nth-child(1)' ) secondary_actions_opener_locator = ( by . By . CSS_SELECTOR , 'td.actions_column > .btn-group > *.btn:nth-child(2)' ) secondary_actions_locator = ( by . By . CSS_SELECTOR , 'td.actions_column > .btn-group > ul.row_actions > li > a, button' ) def decorator ( method ) : @ functools . wraps ( method ) def wrapper ( table , row ) : def find_action ( element ) : pattern = ( '__action_%s' % action_name ) return element . get_attribute ( 'id' ) . endswith ( pattern ) action_element = row . _get_element ( * primary_action_locator ) if ( not find_action ( action_element ) ) : action_element = None row . _get_element ( * secondary_actions_opener_locator ) . click ( ) for element in row . _get_elements ( * secondary_actions_locator ) : if find_action ( element ) : action_element = element break if ( action_element is None ) : msg = ( "Could not bind method '%s' to action control '%s'" % ( method . __name__ , action_name ) ) raise ValueError ( msg ) return method ( table , action_element , row ) return wrapper return decorator
a decorator to bind table region method to an actual row action button .