'Wait for a certain ``type`` of notification, with a certain message
(if specified). Dismiss the notification and return the message.'

def wait_for_notification(self, type=u'notice', message=None, timeout=2):

    notification_selector = u'.notifications-fixed    .notification-{}'.format(type)
    close_button_selector = u'span.btn-close'
    end_time = (time.time() + timeout)
    while (time.time() < end_time):
        notification = self.wait_for(notification_selector, timeout).first
        candidate = notification.find_by_css(u'div').html
        if ((message is None) or (message == candidate)):
            message = candidate
            break
    notification.find_by_css(close_button_selector).first.click()
    self.wait_to_disappear(u'#{}    {}'.format(notification[u'id'], close_button_selector))
    return message
