def get_captcha_image_element(form):
    """
    Return the <img> element in an lxml form that contains the CAPTCHA.

    NOTE: This assumes the first image in the form is the CAPTCHA image. If
    a form has multiple images, maybe use the etree .sourceline attribute to
    figure out which image is closer to the CAPTCHA input? Or crawl through
    the element tree to find the image?

    :param form: An lxml form element.
    :returns: An lxml image element.
    """
    img_el = form.find(".//img")
    if img_el is None:
        raise Exception("Cannot locate CAPTCHA image")
    return img_el