'Click on menu item if not selected.
Menu animation that visualize transition from one selection to
another take some time - if clicked on item during this animation
nothing happens, therefore it is necessary to wait for the transition
to complete first.
Third-level menus are handled differently from others. First, they do
not need to collapse other 3rd-level menu item prior to clicking them
(because 3rd-level menus are atomic). Second, clicking them doesn\'t
initiate an animated transition, hence no need to wait until it
finishes. Also an ambiguity is possible when matching third-level menu
items, because different dashboards have panels with the same name (for
example Volumes/Images/Instances both at Project and Admin dashboards).
To avoid this ambiguity, an argument `src_elem` is used. Whenever
dashboard or a panel group is clicked, its wrapper is returned to be
used as `src_elem` in a subsequent call for clicking third-level item.
This way the set of panel labels being matched is restricted to the
descendants of that particular dashboard or panel group.'

def _click_menu_item(self, text, loc_craft_func, get_selected_func=None, src_elem=None):

    is_already_within_required_item = False
    selected_item = None
    if (get_selected_func is not None):
        selected_item = get_selected_func()
        if selected_item:
            if (text != selected_item.text):
                selected_item.click()
                self._wait_until_transition_ends(self._get_menu_list_next_to_menu_title(selected_item))
            else:
                is_already_within_required_item = True
    if (not is_already_within_required_item):
        item = self._get_item(text, loc_craft_func, src_elem)
        item.click()
        if (get_selected_func is not None):
            self._wait_until_transition_ends(self._get_menu_list_next_to_menu_title(item), to_be_expanded=True)
        return item
    return selected_item
