Selects the input (or button) element to use for form submission.

        :param submit: The bs4.element.Tag (or just its *name*-attribute) that
            identifies the submit element to use. If ``None``, will choose the
            first valid submit element in the form, if one exists.

        To simulate a normal web browser, only one submit element must be
        sent. Therefore, this does not need to be called if there is only
        one submit element in the form.

        If the element is not found or if multiple elements match, raise a
        :class:`LinkNotFoundError` exception.

        Example: ::

            browser = mechanicalsoup.StatefulBrowser()
            browser.open(url)
            form = browser.select_form()
            form.choose_submit('form_name_attr')
            browser.submit_selected()

def choose_submit(self, submit):
        """Selects the input (or button) element to use for form submission.

        :param submit: The bs4.element.Tag (or just its *name*-attribute) that
            identifies the submit element to use. If ``None``, will choose the
            first valid submit element in the form, if one exists.

        To simulate a normal web browser, only one submit element must be
        sent. Therefore, this does not need to be called if there is only
        one submit element in the form.

        If the element is not found or if multiple elements match, raise a
        :class:`LinkNotFoundError` exception.

        Example: ::

            browser = mechanicalsoup.StatefulBrowser()
            browser.open(url)
            form = browser.select_form()
            form.choose_submit('form_name_attr')
            browser.submit_selected()
        """
        # Since choose_submit is destructive, it doesn't make sense to call
        # this method twice unless no submit is specified.
        if self._submit_chosen:
            if submit is None:
                return
            else:
                raise Exception('Submit already chosen. Cannot change submit!')

        # All buttons NOT of type (button,reset) are valid submits
        inps = (self.find_by_type("input", "submit", dict()) +
                self.form.find_all("button"))
        inps = [i for i in inps
                if i.get('type', '').lower() not in ('button', 'reset')]

        # If no submit specified, choose the first one
        if submit is None and inps:
            submit = inps[0]

        found = False
        for inp in inps:
            if (inp.has_attr('name') and inp['name'] == submit):
                if found:
                    raise LinkNotFoundError(
                        "Multiple submit elements match: {0}".format(submit)
                    )
                found = True
            elif inp == submit:
                if found:
                    # Ignore submit element since it is an exact
                    # duplicate of the one we're looking at.
                    del inp['name']
                found = True
            else:
                # Delete any non-matching element's name so that it will be
                # omitted from the submitted form data.
                del inp['name']

        if not found and submit is not None:
            raise LinkNotFoundError(
                "Specified submit element not found: {0}".format(submit)
            )
        self._submit_chosen = True