def select_login_fields(fields):
    """
    Select field having highest probability for class ``field``.

    :param dict fields: Nested dictionary containing label probabilities
        for each form element.
    :returns: (username field, password field, captcha field)
    :rtype: tuple
    """
    username_field = None
    username_prob = 0
    password_field = None
    password_prob = 0
    captcha_field = None
    captcha_prob = 0

    for field_name, labels in fields.items():
        for label, prob in labels.items():
            if label in ("username", "username or email") and prob > username_prob:
                username_field = field_name
                username_prob = prob
            elif label == "password" and prob > password_prob:
                password_field = field_name
                password_prob = prob
            elif label == "captcha" and prob > captcha_prob:
                captcha_field = field_name
                captcha_prob = prob

    return username_field, password_field, captcha_field