Some basic imports: >>> from lxml.html import usedoctest >>> from lxml.html.formfill import fill_form_html The simplest kind of filling is just filling an input with a value: >>> print(fill_form_html(''' ...
''', dict(foo='bar'))) You can also fill multiple inputs, like: >>> print(fill_form_html(''' ... ''', dict(foo=['bar1', 'bar2']))) Checkboxes can work either as boolean true/false, or be selected based on their inclusion in a set of values:: >>> print(fill_form_html(''' ... ''', dict(spam_me=True, type=['viagra', 'other']))) FIXME: I need to test more of this. But I'm lazy and want to use the coverage report for some of this. This module also allows you to add error messages to the form. The errors add an "error" class to the input fields, and any labels if the field has a label. It also inserts an error message into the form, using a function you can provide (or the default function). Example:: >>> from lxml.html.formfill import insert_errors_html >>> print(insert_errors_html(''' ... ''', { ... 'v1': "err1", ... 'v2': "err2", ... 'v3': [None, "err3-2"], ... 'v4': "err4", ... None: 'general error', ... '#fieldset': 'area error', ... }))