模拟输入参数, 然后提交

def mock_input_submit(self, *args, **kwargs):
        """ 模拟输入参数, 然后提交 """
        self.robot.load_page(self.base['homepage'])
        if kwargs.get('force_window_topper'):
            self.force_window_topper()

        if self.base.get('popovers'):
            self.mock_popovers()

        if self.base.get('activate_input'):
            self.robot.mock_click(self.base['activate_input'])

        # 使用了 for else tricks,
        # 正常循环执行条件到 倒数第一个元素,
        # 然后最后一个元素在 else 中触发
        terms = kwargs.get('terms')
        # 如果 terms 结果可能出现 多个, 则需要在此设定需要选择的元素 `index`
        multiple = [0 for _ in terms]
        for i, k in enumerate(kwargs.get('multiple', [])):
            multiple[i] = k

        for i, q in enumerate(self.base['terms'][:-1]):
            self.robot.mock_input(q, terms[i], clear=True, multiple=multiple[i])
        else:
            _submit = False if self.base.get('submit_button') else True
            log.debug('Do submit By last input {}'.format(_submit))
            # if do not force length match of base['terms'] and terms, last_idx required.
            last_idx = len(self.base['terms']) - 1
            self.robot.mock_input(self.base['terms'][last_idx], terms[last_idx], clear=True,
                                  submit=_submit, multiple=multiple[-1])

        if self.base.get('submit_button'):
            log.debug('do submit by button click')
            self.robot.mock_click(self.base['submit_button'])