def add_component(page, item_type, specific_type, is_advanced_problem=False):
 btn = page.q(css='.add-xblock-component .add-xblock-component-button[data-type={}]'.format(item_type))
 multiple_templates = btn.filter((lambda el: ('multiple-templates' in el.get_attribute('class')))).present
 btn.click()
 if multiple_templates:
  sub_template_menu_div_selector = '.new-component-{}'.format(item_type)
  page.wait_for_element_visibility(sub_template_menu_div_selector, 'Wait for the templates sub-menu to appear')
  page.wait_for_element_invisibility('.add-xblock-component .new-component', 'Wait for the add component menu to disappear')
  if is_advanced_problem:
   advanced_tab = page.q(css='.problem-type-tabs a').filter(text='Advanced').first
   advanced_tab.click()
   css = '.problem-type-tabs li.ui-tabs-active a'
   page.wait_for((lambda : (len(page.q(css=css).filter(text='Advanced').execute()) > 0)), 'Waiting for the Advanced problem tab to be active')
  all_options = page.q(css='.new-component-{} ul.new-component-template li button span'.format(item_type))
  chosen_option = all_options.filter(text=specific_type).first
  chosen_option.click()
 wait_for_notification(page)
 page.wait_for_ajax()

def add_component ( page , item_type , specific_type , is_advanced_problem = False ) : btn = page . q ( css = '.add-xblock-component .add-xblock-component-button[data-type={}]' . format ( item_type ) ) multiple_templates = btn . filter ( ( lambda el : ( 'multiple-templates' in el . get_attribute ( 'class' ) ) ) ) . present btn . click ( ) if multiple_templates : sub_template_menu_div_selector = '.new-component-{}' . format ( item_type ) page . wait_for_element_visibility ( sub_template_menu_div_selector , 'Wait for the templates sub-menu to appear' ) page . wait_for_element_invisibility ( '.add-xblock-component .new-component' , 'Wait for the add component menu to disappear' ) if is_advanced_problem : advanced_tab = page . q ( css = '.problem-type-tabs a' ) . filter ( text = 'Advanced' ) . first advanced_tab . click ( ) css = '.problem-type-tabs li.ui-tabs-active a' page . wait_for ( ( lambda : ( len ( page . q ( css = css ) . filter ( text = 'Advanced' ) . execute ( ) ) > 0 ) ) , 'Waiting for the Advanced problem tab to be active' ) all_options = page . q ( css = '.new-component-{} ul.new-component-template li button span' . format ( item_type ) ) chosen_option = all_options . filter ( text = specific_type ) . first chosen_option . click ( ) wait_for_notification ( page ) page . wait_for_ajax ( )
click one of the "add new component" buttons .